C# Java issue with String to Array to String -
i trying convert string array string again. trying achieve in c# have not done c# in while having issues. created following code in java , works fine:
string shtml = "test1\r\ntest2\r\ntest3\r\ntest4\r\ntes5t\r\ntest6\r\ntest7\r\ntest8\r\ntest9\r\ntest10\r\ntest11\r\ntest12\r\ntest13\r\ntes14t\r\n"; int temp = 0; list<string> emailtext = new arraylist<string>(); for(int x = 0; x<shtml.length();x++){ if(shtml.charat(x)=='\n'){ emailtext.add(shtml.substring(temp, x)); temp = x; } } string testingstring=""; for(string words:emailtext){ //system.out.println(words); testingstring+=words; } system.out.println(testingstring);
this works fine in java. following code have c#:
int temp = 0; list<string> emailtext = new list<string>(); (int x = 0; x < shtml.length; x++) { if (shtml[x].equals("\\n")) { emailtext.add(shtml.substring(temp, x)); temp = x; } else { } } string testingstring = ""; //shtml = string.join("\r\n", emailtext.toarray()); foreach (string word in emailtext) { testingstring += word; } console.writeline(testingstring);
the java code outputs fine getting no output c# code. have feeling missing small c# code not sure what, can please help?
thanks in advance
try this: although recommend using string builder larger strings they're immutable.
string yourstring = "this,is,a,example,string"; string newstring = ""; string[] array = yourstring.split(','); foreach (string s in array) { newstring += s; } console.writeline(newstring);
Comments
Post a Comment