Friday, July 31, 2009

How in Visual Basic 2005 can you replace first character of string with a different character?

Dim string1 As String = "Replace me"


Dim string2 As String = string1.Remove(0, 1)


string1 = "D" + string2

How in Visual Basic 2005 can you replace first character of string with a different character?
Sure. You can do this a couple of ways. Just set the string = the new character plus the remaining characters of the string. Look at the Mid, SubStr, and Right functions. All of those should work.
Reply:Here's how to do it using Substring...





Dim oldString As String = "Replace me"


Dim newString As String = "D" %26amp; oldString.Substring(1)


No comments:

Post a Comment