I have a string entered by the user in the text box. I need to insert char ‘#’ in the string if not entered by the user.
expected format : aaa#aa#a
Here is the code to verify and correct the expected format:-
if user entered this: aaaaaa,
if (enteredtext.Length >= 7 && enteredtext.EndsWith(","))
{
if (enteredtext.IndexOf('#', 3, 3) == -1)
enteredtext = enteredtext.Insert(3, "#");
if (enteredtext.IndexOf('#', 6, 6) == -1)
enteredtext= enteredtext.Insert(6, "#");
}
Any other best way to achieve it?
Instead of
if (enteredtext.IndexOf('#', 3, 3) == -1)you can just do: