1

Help! I have a list of records in Excel that I'm copying/pasting into an ASP.NET web page. From there, the C# code parses the records.

This code below works for one of the names, but not another. If, however, I copy/replace the empty space in Excel with a typed space or if I actually backspace and type the name into the webpage with the keyboard, it does work.

It's as if Excel has some odd ghost character in the file I was given for the space on this record. I've pasted in Notepad++ and showed all characters, and I don't see anything special here that's different among the records.

This one works and detects the spaces: Carolyn Bentivegna This one does not: Allan D. Blake

if (fullName.IndexOf(" ") > -1)

1 Answer 1

5

Try the tabspace:

if (fullName.IndexOf("\t") > -1)

Cells copied via excel are separated by a TabSpace and Rows are separated via newlines and carriage return.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm only copying one column of data. Notepad++ shows only newlines (CRLF), no tabs.
There is a problem with the string you have in your excel. See the ascii value here. That is definitely not a space. Its value is 160 - the ascii value should be 32
Thanks! :) I see that now. Any good way on doing this via C# to replace it? I did this and it works, but you can't see the difference to the naked eye: string fullName = fullNameOnly.FullName.Replace(" ", " ");
You can write your own function which will replace any special chars. It should not be difficult. Just check the ascii values of non-printable chars and create a new string using stringbuilder without those chars.
Thanks again. You saved the day for me. :) This works for me now: fullName = fullName.Replace(char.ConvertFromUtf32(160).ToString(), char.ConvertFromUtf32(32).ToString());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.