Hi Ronda,
You can parse using something like regular expressions, to find the data
between runs of spaces. But there is a problem with using that approach with
this kind of file.
Because your file is formatted with fixed-width fields, the program that
wrote it has assumed that it's safe to write spaces into the data, as it
knows that any program reading the file is "supposed to" use the fixed
widths to work out which text goes in which column. (For example, the spaces
in the names, and also in the shipping codes in the first field.) So if your
program works by looking for spaces that separate columns, sometimes it
might actually find a space in the middle of a piece of data and think that
it's a space that marks the gap between two columns. And, if a piece of data
is the maximum length of a field, there might not be a space between it and
the next field at all...
I would suggest that you use String.Substring() to pull out the individual
fields. You can use the Substring() function with two parameters -- the
start of the substring, and its length. So for example, assuming you have a
string variable called theWholeLine with one line of the file in it, to get
the contents of the first field you could use
theWholeLine.Substring(1, 15).TrimEnd()
and to get the second field you could use
theWholeLine.Substring(16, 12).TrimEnd()
...and so on. (I've also used TrimEnd() to remove any trailing white space
from the data.)
HTH
Jason
_____
From: Ronda K [mailto:[EMAIL PROTECTED]
Sent: 28 February 2005 21:23
To: [email protected]
Subject: Re: [AspNetAnyQuestionIsOk] Parsing Text Files
Jason,
If I do an actual import and map the fields you are right I could come
up with a format that I could read. Do you see any way to parse the
text file without importing into Excel - I was trying to avoid that
step for the end user. They just wanted to upload and process.
Curious though that you saw the pattern (e.g. field on 16 characters)
- I guess I have been looking at this file too long and didn't see the
pattern so I will reexamine it ... if that is the case then I can just
parse at specific characters.
I am still interested in knowing though if one can parse and just pick
up the next character after a string of white space ....
Ronda
On Mon, 28 Feb 2005 21:16:51 -0000, Jason Handby <[EMAIL PROTECTED]>
wrote:
>
> Hi Ronda,
>
> It looks to me like your fields are at fixed column positions -- i.e. the
> first field starts at character 1, the next field starts at character
16...
> So I think what you need to do is to select "fixed-width" as your format
> type when you open the file in Excel. You should then be able to drag some
> little sliders around in the import dialog to show Excel where each column
> of data begins and ends.
>
> I've just copied the data from your email, pasted it into a text file and
> read it into Excel, and it was very easy. (I'm using Excel 2003 but I'm
> pretty sure older versions will cope with this too.)
>
> Jason
>
> _____
>
> From: Ronda K [mailto:[EMAIL PROTECTED]
> Sent: 28 February 2005 15:53
> To: [email protected]
> Subject: [AspNetAnyQuestionIsOk] Parsing Text Files
>
> I am dealing with a text file that contains shipping information it is
> coming out of a very archaic system. The file looks something like
> this:
>
> RPS AIR-PP SL29799EA DEBBIE RUSKOWSKY 23322
> 3.00 .00 055108800099191 996060 86658
> RPS AIR-PP SL33098 MICHAEL DEMERS 80631
> 2.00 .00 055108800099153 997340 86658
> RPS AIR-PP SL33103 PASITHORN SUWANABOL 53705
> 4.00 .00 055108800099221 998460 86658
> RPS AIR-PP SL33104 LISA PAYTON 33133
> 3.00 .00 055108800099207 998470 86658
> RPS AIR-PP SL33108 PHILIP ALVAREZ-CORREA 03741
> 3.00 .00 055108800099214 998630 86658
>
> If you open it in Excel each line reads in one cell indicating that
> there is not a tab character in there. This is confirmed when I try
> to create an array and break it on chr(32). I have also tried to
> create an array and break it on chr(9) but that is not working either
> - I get way too many fields. How do I specify to break on the next
> non-space character? I need to get out the shipping method, order #
> and tracking # when it is all said and done.
>
> TIA,
>
> --
> Ronda Pederson
> MVP ASP.Net
>
> Yahoo! Groups Sponsor
>
> ADVERTISEMENT
>
>
<http://us.ard.yahoo.com/SIG=1296ve9cq/M=298184.6018725.7038619.3001176/D=gr
>
oups/S=1705006764:HM/EXP=1109692416/A=2593423/R=0/SIG=11el9gslf/*http://www.
> netflix.com/Default?mqso=60190075> click here
>
>
<http://us.adserver.yahoo.com/l?M=298184.6018725.7038619.3001176/D=groups/S=
> :HM/A=2593423/rand=880398972>
>
> _____
>
> Yahoo! Groups Links
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
>
> * To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
>
<mailto:[EMAIL PROTECTED]
> e>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service
> <http://docs.yahoo.com/info/terms/> .
>
>
> [Non-text portions of this message have been removed]
>
>
> Yahoo! Groups Links
>
>
>
>
>
--
Ronda Pederson
MVP ASP.Net
Yahoo! Groups Sponsor
ADVERTISEMENT
<http://us.ard.yahoo.com/SIG=1290udjrq/M=298184.6018725.7038619.3001176/D=gr
oups/S=1705006764:HM/EXP=1109712211/A=2593423/R=0/SIG=11el9gslf/*http://www.
netflix.com/Default?mqso=60190075> click here
<http://us.adserver.yahoo.com/l?M=298184.6018725.7038619.3001176/D=groups/S=
:HM/A=2593423/rand=425678289>
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]
e>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/