Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a string with carriage return seperators 1

Status
Not open for further replies.

00Stump

Programmer
Nov 20, 2006
7
US
I am working on an application in C# that is running on a Windows Mobile devise. The devise captures bar code data, that I need to be able to work with as individual elements. It seems each element is seperated by carriage returns, but I can't seem to be able to seperate the acquired text into seperate elements.

I tried writing the recieved data to a text file, and it looks like this:

Matthew David Davignon Davignon
MRCP, MBBS
University of Western Massachusetts
33 New Montgomery St., Ste 142
Rheumatology Dept., 14th Floor
Research Triangle Pk,  94105
United Arab Emirates
01-234-567-8901
10-987-654-3210
EXHIB





Does anyone have any ideas for seperating the values? For example, I need "Mathew David" to be seperated from the rest of text so that it can be entered into a database as the name field... and "Davignon Davignon" to be seperated to be inserted into the company name field in the table, etc.

Anyones help is greatly appreciated!

Thanks in advance!
 
I believe a barcode starts with the * symbol at the start and end of the code. So if you were to use a barcode font to print the labels you would print

*yourinfo*

As for the newline character. Try capturing the string and splitting it using the System.Environment.NewLine character. A simple way to split a string is to use a regex (Regular Expression) split.
 
Thanks JurkMonkey! I have played with the regex split, and it doesn't seem to be giving me the output I was expecting. What syntax would you use for the split?

Thanks!
 
I am wandering if what I am assuming are carriage returns are not acutally carriage returns. No matter how I try to split the string, I am ending up with data that still contains the square characters. Can you think of anything else they might be?
 
I would use code like this to determine exactly what the characters actually are:

string testString = @"Matthew David Davignon Davignon
MRCP, MBBS
University of Western Massachusetts
33 New Montgomery St., Ste 142
Rheumatology Dept., 14th Floor
Research Triangle Pk,  94105
United Arab Emirates
01-234-567-8901
10-987-654-3210
EXHIB";
char[] testChars = testString.ToCharArray();
foreach(char thisChar in testChars)
{
System.Console.WriteLine(thisChar + " = " + Convert.ToInt16(thisChar));
}


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks EBGreen! The following is part of what I got...

=2
=2
=2
M=77
a=97
t=116
t=116
h=104
e=101
w=119
=32
D=68
a=97
v=118
i=105
d=100
=3
=32
=3
D=68
a=97
v=118
i=105
g=103
n=110
o=111
n=110
=32
D=68

Sorry for being dumb, but what do I reference the int value to?

Thanks,
Dan
 
disregard my last... it was a dumb question.
 
So it looks like the data that I recieve from the bar code scanner input has 3 ASCII Start of Text characters, then each field is ended with an end of text character.

Does anyone know how to seperate each field by those ASCII characters?

Thanks,
Dan
 
use the String.Split Method ...

here is a sample


for you your splitter should be that asc for the box that is 3.

you could just drop the first 3 chars of each line if they are always junk you dont need. or you could loop through each character of the line and ditch the junk chars until you get to an actual meaningful value (a letter asc code >= 65)

HTH
 
How would my syntax be for the following line, with the asc character?

char[] splitter = {';'};

Thanks for your help!
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top