Reputation: 823
I need validation for string to comply with next:
How this can be done?
Updated sorry missed that should only be one delimiter char at start and at the end
Upvotes: 0
Views: 546
Reputation: 1076
If I understood your question right, this should do:
char delimiter = ...
string delimiterString = delimiter.ToString();
string s = ...
bool right = !s.Contains(' ')
&& s.StartsWith(delimiterString)
&& s.EndsWith(delimiterString)
&& !s.Substring(1,s.Length-2).Contains(delimiter);
Upvotes: 1
Reputation: 1374
Use regex...Assuming # as delimeter and zero characrters between as acceptable.
Regex rx=new Regex("^#+[^\s]*#$");
return rx.IsMatch(teststring);
Upvotes: 1