Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok, I'm getting the current time like so:

 

Time = Today.Now.ToShortTimeString

 

At this time, the variable reads: "8:40 PM"

 

I want to remove the space between "8:40" and "PM"

 

I try these statements:

 

Time = Today.Now.ToShortTimeString.Trim()

Time = Trim(Today.Now.ToShortTimeString)

Time = Today.Now.ToShortTimeString.Trim(" ")

Time = Today.Now.ToShortTimeString
Time = Time.Trim()

 

I think I know why. When I set Time to be equal to the current time, it sets the reference to the time, rather than copying over the actual string (array of characters).

 

This is annoying as heck. Any suggestions?

  • *Experts*
Posted
Ok, I'm getting the current time like so:

 

Time = Today.Now.ToShortTimeString

 

At this time, the variable reads: "8:40 PM"

 

I want to remove the space between "8:40" and "PM"

 

I try these statements:

 

Time = Today.Now.ToShortTimeString.Trim()

Time = Trim(Today.Now.ToShortTimeString)

Time = Today.Now.ToShortTimeString.Trim(" ")

Time = Today.Now.ToShortTimeString
Time = Time.Trim()

 

I think I know why. When I set Time to be equal to the current time, it sets the reference to the time, rather than copying over the actual string (array of characters).

 

This is annoying as heck. Any suggestions?

This will work:

Time = Now.ToShortTimeString.Replace(" ", "")

 

Jon

Posted

I did this workaround:

 

Hour = Now.Hour.ToString

Minutes = Now.Minutes.ToString

 

I already have many functions for converting time back and forth in my program so this works just fine. I could clean up my code A LOT once I learn how to use the VB internal time functions... mostly I had problems with adding time together.

 

Like so many projects, the time grows near (and abruptly without notice) and subtlety and finesse goes right out the window :D

 

Thank you for your help :)

  • *Experts*
Posted

Why not just use ToString with the right format, such as "hh:mmtt"?

Dim s As String = Today.ToString("hh:mmtt")

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Hummm... Yes it work more than perfectlly.

 

As I said before... Nerseus rocks ! :p

 

N.B.: The way Nerseus do it is more optimized. Better take this way.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...