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

Changing Text

Status
Not open for further replies.

XMSMS

ISP
Oct 27, 2003
9
GB
Hi All,

I have a text file that is arranged as follows:

username1, password1
username2, password2
username3, password3

What i want my code to do for each line of this text file, is put usernamex into a variable and passwordx into a variable, so that they can be written to a different file.

basicaly, i need to convert a line like:

username1, password1

into a line like:

<uname=username1>
<pword=password1>
 
Try something like this:
Code:
Set fso=CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set t1=fso.OpenTextFile(&quot;\path\to\input&quot;,1) 'ForReading
Set t2=fso.OpenTextFile(&quot;\path\to\output&quot;,2) 'ForWriting
While Not t1.AtEndOfStream
  buf=t1.ReadLine
  arr=Split(buf,&quot;,&quot;)
  t2.WriteLine &quot;<uname=&quot; & arr(0) & &quot;>&quot;
  t2.WriteLine &quot;<pword=&quot; & arr(1) & &quot;>&quot;
Wend
t1.Close
t2.Close

Hope This Help
PH.
 
hi thanks for that, it does exactly what i'm after.
i have come across one problem tho, if i want to do the following, it doesnt work:

t2.WriteLine &quot;<variable name=&quot;Name&quot;>o212</variable>&quot;

i'm guessing its because of the extra &quot;&quot;, how do i get around this
 
Try this:
Code:
t2.WriteLine &quot;<variable name=&quot; & Chr(34) & &quot;Name&quot; & Chr(34) & &quot;>o212</variable>&quot;
or this:
Code:
t2.WriteLine &quot;<variable name=&quot;&quot;Name&quot;&quot;>o212</variable>&quot;

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top