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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hitting a newline or tab character

Status
Not open for further replies.

sshafe

Programmer
Oct 18, 2002
71
0
0
US
I am reading through a text file by character. The way the file is set up is User Name <tab> User Group <newline> I've been researching and cannot find a way to say if a <tab> or <newline> character is encountered, assign next character string to new variable name. (I.E...Once <tab> is encountered, end assigning characters to USER_NAME. Once <newline> is encountered, end assigning characters to USER_GROUP, loop)

Any ideas of how to set up this do until statement? Or a better way to set this up?

Thanks :)

**(The USER_NAME and USER_GROUP are variable lengths so I cannot just read by inputFile.Read(8) or so.)
 
Try looking for chr(9) TAB or chr(13) Return in the string.

eg If Mid(str, i, 1) = chr(9) Then...

Hope that helps

 
Much better is to use vbTab and vbNewLine. VBScript has a number of intrinsic string constants of this nature. They help others make more sense of your code and reduce errors at the same time.

Note that vbNewLine is platform-dependent. For example on a Windows machine vbNewLine is equal to vbCrLf, while on a Unix platform vbNewLine is equal to vbLf and on a Mac vbNewLine is equal to vbCr.

This assumes you really meant newline however. If you know the data has CR delimiters you'd explicitly use vbCr. vbNewLine is for contexts such as strings read from native stream files.

See the &quot;String Constants&quot; section of the Windows Script Technology documentation (help file).

 
Seeing what you seem to be up to with this, I wrote a new FAQ:

Read delimited (and fixed-field!) data in VBScript with ADO?
faq329-3323
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top