Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a value in a string at certain positions c#

Tags:

string

c#

I have a program that gets a string from a method. I want to know how to insert a string value to that string at certain positions.

For example:

mystring = "column1 in('a','b')column2 in('c','d')column3 in('e','f')";

Here, how would I insert the string value " and " after every occurance of the character ')' in mystring?

PS. If possible, also include how not to insert it right at the end.

like image 489
zohair Avatar asked Dec 09 '25 12:12

zohair


1 Answers

Probably the simplest:

mystring = mystring.Replace(")", ") and ");
mystring = mystring.Substring(0, mystring.Length - " and ".Length);
like image 188
Joel Avatar answered Dec 11 '25 02:12

Joel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!