I hope I can save someone some time from this little mind boggler....
I had a string, I wanted to change one particular part of the string... NO PROBLEM -- use .Replace right? well, sort of.
Strings are immutable objects and cannot be changed -- so saying
msgText.Replace ("5 of 6", "3 of 5")
may look good and will not even give you an error (unfortunately) BUT it also WILL NOT WORK!
You have two options... create a different string to house the Replaced string OR create a stringBuilder.
I chose to use a new string and the .Replace worked great.
myNewText = msgText.Replace ("5 of 6", "3 of 5")
all is well again.
Showing posts with label Strings. Show all posts
Showing posts with label Strings. Show all posts
Monday, June 23, 2008
Wednesday, June 11, 2008
STRINGS and their stuff.
GET RID OF TRAILING COMMA:
(you have built something that leaves you with a string with a comma at the end and you want it gone -- use Left minus 1 of the length of string!)
dim myString as String = "1,2,3,4,5,"
myString = Left(myString, myString.Length - 1)
RESULT: myString = "1,2,3,4,5"
more to come...
(you have built something that leaves you with a string with a comma at the end and you want it gone -- use Left minus 1 of the length of string!)
dim myString as String = "1,2,3,4,5,"
myString = Left(myString, myString.Length - 1)
RESULT: myString = "1,2,3,4,5"
more to come...
Subscribe to:
Posts (Atom)
