hi all,
I have a string "FS:A151940.A-CM4;4" and have a integer value stored in a variable num.... now i want the string to be modified as "FMS:A151940.A-CM4;*" where value of num must be present instead of *... please help me out with this !!

I am a little confused

"FS:A151940.A-CM4;4"
"FMS:A151940.A-CM4;*"

Does the M mean anything or is it a Typo

you have to use the Replace command.

string code = "FS:A151940.A-CM4;*"
int num = 5;
code = code.Replace("*",num.toString());
MessageBox.Show(code);

String.Replace("oldText","newText");
Basically search for oldText and replace it with the newText;

Hope this helped, mark as solved if solved
Peace

Edited 6 Years Ago by finito: n/a

hey, one correction...its not just the * there...already some other number ll be present ther , jus added a * for better understanding.the number already present must be replaced with the valu of num..

can you be more clear I am not sure what you mean?

are u saying that the * will not be the same?

just replace '*' with what you get?

if the string you mentioned will be the same until the semicolon, you can use something like this

string MyString = "FS:A151940.A-CM4;4";
string aString = MyString.Substring(0, MyString.IndexOf(';')) + value.ToString();

Ionut

if the string you mentioned will be the same until the semicolon, you can use something like this

string MyString = "FS:A151940.A-CM4;4";
string aString = MyString.Substring(0, MyString.IndexOf(';')) + value.ToString();

Ionut

This should work if the string doesn't change length.
or rather if value is always after ;

This question has already been answered. Start a new discussion instead.