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!

Replacing Text

Status
Not open for further replies.

XMSMS

ISP
Joined
Oct 27, 2003
Messages
9
Location
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>


Help is very much appreciated.
 
Try this...

&quot;File1.txt&quot; is the file you are Reading...
&quot;File2.txt&quot; is the file you are Creating...


Code:
On Error GoTo NoFile
Open &quot;File1.txt&quot; For Input As #1
Open &quot;File2.txt&quot; For Output As #2
If Not EOF(1) Then
  Do
    Line Input #1, A$
    i% = InStr(1, A$, &quot;,&quot;)
    If i Then
      User$ = RTrim$(LTrim$(Left$(A$, i - 1)))
      Pass$ = RTrim$(LTrim$(Right$(A$, Len(A$) - i)))
      Print #2, &quot;<uname=&quot; + User$ + &quot;>&quot;
      Print #2, &quot;<pword=&quot; + Pass$ + &quot;>&quot;
    End If
  Loop Until EOF(1)
End If
Close
End

NoFile:
Print &quot;File Not Found!!!&quot;
Close
End


****** Not Tested... I only Have VB on this PC... If it does not work, Let me know and I will Fix It...

*Note:
If It Does Not Work...
This Line:
Pass$ = RTrim$(LTrim$(Right$(A$, Len(A$) - i)))
Might need to be:
Pass$ = RTrim$(LTrim$(Right$(A$, (Len(A$) - i) - 1)))

Good Luck,
-Josh S

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top