hallo,
I would need to replace a string in another string. The problem is that I would like the replace function to be case insensitive. Do you have a suggestion for this? thanks
string TargetString; // We replace here
string key; // replace what
string NewKey; // replace with this
We will find the position ot which the string is, remove the old and add a new one. But to be case sensitive we will search when both strings are in Lower
int pos =targ.ToLower().IndexOf(key.ToLower);
// if there is a match
if (pos <>-1 )
{
// remove old
targ.Remove(pos,key.Length);
// add the newkey
targ.Insert(pos,Newkey);
}
I just forgot the pos function and I am not sure weather pos returns 0 or -1 if sub string is not found.
try RegEx:
<script runat="Server">
sub Page_Load
Dim StringToFind="ASD"
Dim RegExp as new RegEx(StringToFind,1)
Dim TestString as string="asd"
response.write("Test string is -")
response.write(RegExp.replace(TestString,""))
end sub
</script>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.