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

.net - Bulk insert via Dapper is slower than inserting rows one-by-one -

shared memory - gstreamer shmsrc and shmsink with h264 data -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -