Denaes Posted April 22, 2004 Posted April 22, 2004 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? Quote
*Experts* jfackler Posted April 22, 2004 *Experts* Posted April 22, 2004 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 Quote
Denaes Posted April 22, 2004 Author Posted April 22, 2004 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 :) Quote
*Experts* Nerseus Posted April 22, 2004 *Experts* Posted April 22, 2004 Why not just use ToString with the right format, such as "hh:mmtt"? Dim s As String = Today.ToString("hh:mmtt") -Nerseus Quote "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
Arch4ngel Posted April 22, 2004 Posted April 22, 2004 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. Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.