Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String manipulation 1

Status
Not open for further replies.

vietnam97

Programmer
Sep 18, 2000
48
Can someone show me how to replace a character at a specified position in a string?
For example: I want to replace character "1" with "0" at the position 5 of the string "1111111111", so the output should be "1111011111" [sig][/sig]
 
This might help. It's from MSDN.
Code:
Dim MyString
MyString = "The dog jumps"             ' Initialize string.
Mid(MyString, 5, 3) = "fox"            ' MyString = "The fox jumps".
Mid(MyString, 5) = "cow"               ' MyString = "The cow jumps".
Mid(MyString, 5) = "cow jumped over"   ' MyString = "The cow jumpe".
Mid(MyString, 5, 3) = "duck"           ' MyString = "The duc jumpe".
If you are working with numbers, you should be able to convert to a string data type, do the switch, and then convert back to your number data type.

I haven't tested this.
HTH.
Patty [sig][/sig]
 
Hiya,

mid will do it fine. The syntax is;

strResult = mid(string,start as long,[length as long])

where string is the string you're passing in, start is the character position within string from where you wish to start returning strResult and the optional length is the number of charcters you want to return from this start point. If you don't supply length, mid will return all charcters from the start position to the end of the string.

Cheerio,

Paul
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top