c# - String.Replace() will not change the source string of the variable -


this question has answer here:

i have following code inside c# application:-

 string[] excludechar = { "|", "\\", "\"", "'", "/", "[", " ]", ":", "<", " >", "+", "=", ",", ";", "?", "*", " @" };  var currentgroupname = curitemsitename;  (int = 0; < excludechar.length; i++)        {          if (currentgroupname.contains(excludechar[i]))              currentgroupname.replace(excludechar[i], "");               }  site.rootweb.sitegroups.add(currentgroupname) 

now in abive code currentgroupname variable passing inside .add function have special characters have replaced inside loop. can adivce if can modify code .replace replacing original string of currentgroupname ...

you not assigning "replaced" string currentgroupname

 string[] excludechar = { "|", "\\", "\"", "'", "/", "[", " ]", ":", "<", " >", "+", "=", ",", ";", "?", "*", " @" };  var currentgroupname = curitemsitename;  (int = 0; < excludechar.length; i++)        {          if (currentgroupname.contains(excludechar[i]))              currentgroupname = currentgroupname.replace(excludechar[i], "");               }  site.rootweb.sitegroups.add(currentgroupname) 

Comments

Popular posts from this blog

c++ - CPP, 'X' button listener -

Get Max value from table in hibernate -

php - Alamofire request parameters empty -