Compare string in c# for spaces in middle -


i want compare string in c# username duplicate.but problem how can compare strings having symbol , spaces in them.for example

one username : ak-username second username : ak - username

first without space , second space in middle along symbol.

i cannot remove spaces compare user can [ak username]

you can split string , rejoin it

string str="ak username"; string str1 = "akusername"; string[] splittedstrings = str.split(" "); str = "";  for(int i=0; i<splittedstrings.length; i++) {   str += spittedstrings[i]; }  if(string.equals(str,str1,stringcomparison.ordinalignorecase)) {   messagebox.show("equal"); } 

edit: saw comments below saying want "ak-username" , "ak - username" equal. refactoring code , writing below!

string str="ak - username"; string str1 = "ak-username"; string[] splittedstrings = str.split("-"); str = "";  for(int i=0; i<splittedstrings.length; i++) {   str += spittedstrings[i].trim(); }  if(string.equals(str,str1,stringcomparison.ordinalignorecase)) {   messagebox.show("equal"); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -