Thursday, July 30, 2009

Can you replace one occurence in a string with C#?

I have a string, forexample aaabcc


and I want to replace only one 'a' by 'b' and not all of the a's...any ideas of how I could do it please?

Can you replace one occurence in a string with C#?
A better approach for this might be to let the program do the hard work:





Take your inbound value and split it by the delimiter into an array:





string[] strValues = strInbound.Split(',');


//Note: using ' to enclose the delimiter implies the char type in C#


//Use ","c in VB.NET





Then you can spin thru the array and replace all occurences of String.Empty ("") with "NULL". Then you also have a data structure from which to construct your database query instead of just another string.


No comments:

Post a Comment