want to remove first and last character of any word by using regex.... FOr example..
(HELLO) (WORLD) will return === HELLO WORLD
and (HE/LLO) (WO/RLD) will return ====== HE/LLO WO/RLD
or //Hello WOrld/ will return ========= Hello WOrld
or (HELLO) (W/ORLD) STACKOVERFLOW) will return === HELLO W/ORLD STACKOVERFLOW
(He(Lo) Wo(R)ld will return ===== He(Lo Wo(R)ld
I dun want to replace all parenthesis ..I wish to replace First and last parenthesis of any word.....
I m trying this ...
temp = Regex.Replace(temp, @"^[!@#$%^&*()_+=[{]};:<>|./?,\'""-]+", " ");
BUT this regex equation ONly remove FIRSt CHaracter IF FOund....
Loading
VulpesPosted Sep 9, 2011, 10:42 AM
There was a suggestion in your post that you might want to remove other characters as well but I wasn't clear what they were.
Roy SPosted Sep 9, 2011, 9:25 AM
for (int i = 1; i < temp.Length - 1; i++)
{
if (temp[i] == ' ')
{
temp = temp.Remove(i - 1, 1).Remove(i, 1);
i--;
}
}
temp = temp.Substring(1, temp.Length - 2); //Remove first and last