i have a parser wherein i have created a textbox which accepts the text from the user. I want to display the text within the special characters. The inout string can contain string along with special characters. special characters lik ~ |. i want to display the text between these two characters. If the input string doesnt contain any characters it shud display the input string as it is. els it shud display the text between any two spcial charaters.
Please help me in this regard.
Thanks in advance,
Avinash
Loading
Avinash YoganandPosted Mar 9, 2011, 1:27 AM
VulpesPosted Mar 8, 2011, 4:29 AM
List
char spec1 = '~'; // or whatever
char spec2 = '|'; // or whatever
bool started = false;
foreach(char c in txtInput.Text)
{
if(c == spec1)
{
started = true;
}
else if (c == spec2)
{
started = false;
break;
}
else if(started)
{
list.Add(c);
}
}
if (list.Count > 0 && !started) // if started were still 'true' spec2 could not be present
{
txtOutput.Text = new string(list.ToArray());
}
else
{
textOutput.Text = txtInput.Text;
}
Soft CornerPosted Mar 8, 2011, 1:26 AM
Call This Method & pass your string to this method , that's it
public static string RemoveSpecialCharacters(string str)
{
return Regex.Replace(str, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled);
}