I wrote a script that reads an input file ('input.txt') that creates
an output file ('output.txt') that massages the data and output it to
be use as a metadata file.

One of the things I'm trying to do (but having problems) is to read a
record in the input file and grab the first letter of the word in the
row to create an index tag only using the 'first' character.

HERE IS A EXAMPLE of my input file and what I would like to create in
my output file. I'm trying to substring the first character without
any luck.

******[ 'input.txt' ]******
Mary
Mike
Joe
Tom
Larry
Dick
James
Paula
Jason

******[ 'output.txt' ]******
category="Index",M
category="Index",M
category="Index",J
category="Index",T
category="Index",L
category="Index",D
category="Index",J
category="Index",P
category="Index",J


For example: when my program reads the first row 'Mary', it will
output 'category="Index",M', and so on, till end of file. Everything
else works good, but having problems is sub-stringing.

Thanks! Bre

Re: SUB-STRINGing in VBScript by James

James
Mon Dec 26 19:17:42 CST 2005

"bre jones" <brejones@msu.edu> wrote in message
news:6441r15em1ri443f75kh238ku36jojmt94@4ax.com...
> I wrote a script that reads an input file ('input.txt') that creates
> an output file ('output.txt') that massages the data and output it to
> be use as a metadata file.
>
> One of the things I'm trying to do (but having problems) is to read a
> record in the input file and grab the first letter of the word in the
> row to create an index tag only using the 'first' character.
>
> HERE IS A EXAMPLE of my input file and what I would like to create in
> my output file. I'm trying to substring the first character without
> any luck.
>
> ******[ 'input.txt' ]******
> Mary
> Mike
> Joe
> Tom
> Larry
> Dick
> James
> Paula
> Jason
>
> ******[ 'output.txt' ]******
> category="Index",M
> category="Index",M
> category="Index",J
> category="Index",T
> category="Index",L
> category="Index",D
> category="Index",J
> category="Index",P
> category="Index",J
>
>
> For example: when my program reads the first row 'Mary', it will
> output 'category="Index",M', and so on, till end of file. Everything
> else works good, but having problems is sub-stringing.
>
> Thanks! Bre

I think you are either looking for the 'Left' or 'Mid' string function.
See if this does what you want:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim oFSO, sLine, oInpFile, oOutFile
Dim sInpFileName, sOutFileName

sInpFileName = "input.txt"
sOutFileName = "output.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oInpFile = oFSO.OpenTextFile(sInpFileName, 1)
Set oOutFile = oFSO.OpenTextFile(sOutFileName, 2, True)

Do Until oInpFile.AtEndOfStream
sLine = oInpFile.ReadLine
If Len(sLine) Then
oOutFile.Writeline "category=""Index""," & Left(sLine, 1)
End If
Loop

oInpFile.Close
oOutFile.Close
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Re: SUB-STRINGing in VBScript by bre

bre
Mon Dec 26 21:02:05 CST 2005

awesome, it's Left.

On Mon, 26 Dec 2005 19:17:42 -0600, "James Whitlow"
<jwhitlow@letter.com> wrote:

>"bre jones" <brejones@msu.edu> wrote in message
>news:6441r15em1ri443f75kh238ku36jojmt94@4ax.com...
>> I wrote a script that reads an input file ('input.txt') that creates
>> an output file ('output.txt') that massages the data and output it to
>> be use as a metadata file.
>>
>> One of the things I'm trying to do (but having problems) is to read a
>> record in the input file and grab the first letter of the word in the
>> row to create an index tag only using the 'first' character.
>>
>> HERE IS A EXAMPLE of my input file and what I would like to create in
>> my output file. I'm trying to substring the first character without
>> any luck.
>>
>> ******[ 'input.txt' ]******
>> Mary
>> Mike
>> Joe
>> Tom
>> Larry
>> Dick
>> James
>> Paula
>> Jason
>>
>> ******[ 'output.txt' ]******
>> category="Index",M
>> category="Index",M
>> category="Index",J
>> category="Index",T
>> category="Index",L
>> category="Index",D
>> category="Index",J
>> category="Index",P
>> category="Index",J
>>
>>
>> For example: when my program reads the first row 'Mary', it will
>> output 'category="Index",M', and so on, till end of file. Everything
>> else works good, but having problems is sub-stringing.
>>
>> Thanks! Bre
>
> I think you are either looking for the 'Left' or 'Mid' string function.
>See if this does what you want:
>
>'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Dim oFSO, sLine, oInpFile, oOutFile
>Dim sInpFileName, sOutFileName
>
>sInpFileName = "input.txt"
>sOutFileName = "output.txt"
>
>Set oFSO = CreateObject("Scripting.FileSystemObject")
>
>Set oInpFile = oFSO.OpenTextFile(sInpFileName, 1)
>Set oOutFile = oFSO.OpenTextFile(sOutFileName, 2, True)
>
>Do Until oInpFile.AtEndOfStream
> sLine = oInpFile.ReadLine
> If Len(sLine) Then
> oOutFile.Writeline "category=""Index""," & Left(sLine, 1)
> End If
>Loop
>
>oInpFile.Close
>oOutFile.Close
>'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>