c# - Check whether a string contain '&' character only -


how check whether string contains "&" only. mean if user enter & or &&& or string of '&'. please note http://myurl.com/&var=79 or should ignored. should check string contains & character. please me!!!

i'm sure there better way regex here possible solution:

class program     {         static void main(string[] args)         {             char testchar = '&';             string test1 = "&";             string test2 = "&&&&&&&&&&";             string test3 = "&&&&&&&u&&&&&&&";              console.writeline(checkifonly(testchar, test1)); // true             console.writeline(checkifonly(testchar, test2)); // true             console.writeline(checkifonly(testchar, test3)); // false             console.writeline(checkifonly('u', test3));      // false             console.writeline(checkifonly('u', "u"));      // true             console.writeline(checkifonly('u', "uuuu"));      // true           }          static bool checkifonly(char testchar, string s)         {             foreach (char c in s)             {                 if (c != testchar) return false;             }             return true;         }      } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -