Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
When I try to read strings from excel sheet I am getting following format of strings in to an array[0].Through split(',') I am getting
"\"Title\" value. Can any one please advice me how to suppress "\" from it







[0] = "\"Title\",\"First Name\",\"Middle Name\",\"Last Name\",\"Suffix\",\"Company\",\"Department\",\"Job Title\",\"Business Street\",\"Business Street 2\",\"Business Street 3\",\"Business City\",\"Business State\",\"Business Postal Code\",\"Business Country/Regi...



Thanks
Posted

before you split the strings, remove the \" from it using the string.replace function as in:

C#
arrString[0] = arrString[0].Replace("\"",string.Empty);


Then, do your split.
 
Share this answer
 
Comments
Bikash Shrestha From Nepal 15-Oct-10 16:23pm    
Do you agree with the statement of Abhinav s :- "Split can only split a string based on a single character." ???
William Winner 15-Oct-10 16:50pm    
no...and I never said that I did...in fact, I believe I said that your answer was technically correct.


string aspdotnet, serverName, domainName, domainExtension;
aspdotnet = "www.aspdotnet.in";
string[] arr = aspdotnet.Split('.');
serverName = Convert.ToString(arr[0]);
domainName = Convert.ToString(arr[1]);
domainExtension = Convert.ToString (arr[2]);

OUT PUT :

serverName ="www"
domainName ="aspdotnet"
domainExtension ="in"


For more information this link may help you

For more information this link may help you

Click here.
 
Share this answer
 
C#
string value = "shirt\r\ndress\r\npants\r\njacket";
        //
        // Use a new char[] array of two characters (\r and \n) to break
        // lines from into separate strings. Use "RemoveEmptyEntries"
        // to make sure no empty strings get put in the string[] array.
        //
        char[] delimiters = new char[] { '\r', '\n' };
        string[] parts = value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
 
Share this answer
 
Comments
William Winner 15-Oct-10 13:13pm    
Technically this works, but really, you're not splitting based on the double quotes in this case, you just want to remove them.
Split can only split a string based on a single character.

You will need to remove the "\" from all strings in the split array, after the splitting has occured.
 
Share this answer
 
Comments
William Winner 15-Oct-10 13:11pm    
or instead of doing them one by one, you could remove it from the string before splitting it.
You should be reading the data keeping in mind it is in CSV format. Try putting a comma in one of the Excel cells then export that as CSV and see what you get. CSV is a common format... Google it and you should get some ideas for how to handle it. I know there is at least one library out there to read it for you.

But the simple answer you are probably looking for (also the wrong road to go down) is that you can use the Replace function to replace \" with " (or with nothing, if that is your preference).
 
Share this answer
 


Split string using c#





string aspdotnet, serverName, domainName, domainExtension;
aspdotnet = "www.aspdotnet.in";
string[] arr = aspdotnet.Split('.');
serverName = Convert.ToString(arr[0]);
domainName = Convert.ToString(arr[1]);
domainExtension = Convert.ToString (arr[2]);

OUT PUT :

serverName ="www"
domainName ="aspdotnet"
domainExtension ="in"


For more information this link may help you

For more information this link may help you

Click here.
 
Share this answer
 
string strData = "a,b,c,d,e,f,g,h,i,j";
char[] separator = new char[] { ',' };
string[] strSplitArr = strData.Split(separator);
foreach (string arrStr in strSplitArr)
{
Response.Write(arrStr + "" );
}


here it is to remove comma u can use as per ur requirement like.
 
Share this answer
 
Comments
William Winner 15-Oct-10 13:12pm    
he already know how to do the split. His problem was that the text was coming in with the double quotes surrounding the string types and he didn't want the double quotes around the text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900