Camillia
asked on
How to find the last character in string and replace it
I have a string like this
var filterString ="WHERE ( { StrToMember( @BrandId0 ) }, { StrToMember( @RegistrationTypeId0 ) } )";
I want to replace the last ")" with blank. I did this but it looks like it replaces the entire string with blank.
var filterString ="WHERE ( { StrToMember( @BrandId0 ) }, { StrToMember( @RegistrationTypeId0 ) } )";
I want to replace the last ")" with blank. I did this but it looks like it replaces the entire string with blank.
filterString = filterString.Last().ToString().Replace(")", "");
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and what is that "foo"??
replace "foo" with ")" - thats the character you want to replace
ASKER
There's no way to do this with LINQ??
Check this:
http://stackoverflow.com/questions/10607104/linq-query-for-string-replace
http://frightanic.wordpress.com/2007/06/08/regex-match-last-occurrence/
For most string operations, you would be better off (conciseness) if you use regular expressions rather than LINQ. Will get back to you on LINQ solution too.
http://stackoverflow.com/questions/10607104/linq-query-for-string-replace
http://frightanic.wordpress.com/2007/06/08/regex-match-last-occurrence/
For most string operations, you would be better off (conciseness) if you use regular expressions rather than LINQ. Will get back to you on LINQ solution too.
Hi Camilla;
How about just trimming off the last ) from the string
How about just trimming off the last ) from the string
filterString = filterString.TrimEnd(')');
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I'll give both a try...Fernando's and s_chilkury.
I don't want to trim ALL parens....just the last one.
I don't want to trim ALL parens....just the last one.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Let me try it. I'll post back.
ASKER