6 Replies - 633 Views - Last Post: 16 January 2013 - 12:08 PM Rate Topic: -----

#1 xilith117  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 13-August 11

New line when writing to text file

Posted 15 January 2013 - 04:55 PM

I want my program to read through a text file and insert a new line in the file every time it finds the letter "v".

text file: "v 100 200 300v 20 goop glopv 300 2.9"
Output:
"
v 100 200 300
v 20 goop glop
v 300 2.9"

here is what I have so far:

fso = CreateObject("Scripting.FileSystemObject")
            inputFile = fso.OpenTextFile(ofd.FileName, 1)
            str = inputFile.ReadAll
str = Replace(str, "v", "*new line* & "v")



Thanks. :)/>

Is This A Good Question/Topic? 0
  • +

Replies To: New line when writing to text file

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3246
  • View blog
  • Posts: 10,887
  • Joined: 12-December 12

Re: New line when writing to text file

Posted 15 January 2013 - 05:54 PM

str = Replace(str, "v", "\nv")
Was This Post Helpful? 0
  • +
  • -

#3 xilith117  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 13-August 11

Re: New line when writing to text file

Posted 15 January 2013 - 08:48 PM

that just puts an extra backslash before each v in the textfile :/
"\v 10 0 10\v 9.487180 0 10\v 8.974360 0 10\v 8.461538 0 10\v 7.948718 0 10\v 7.435898"
Was This Post Helpful? 0
  • +
  • -

#4 rob2k9  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 7
  • Joined: 15-January 13

Re: New line when writing to text file

Posted 16 January 2013 - 03:26 AM

this could be done esy buy just loading your text into a string and then using split to split your text at every v
Was This Post Helpful? 0
  • +
  • -

#5 rob2k9  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 7
  • Joined: 15-January 13

Re: New line when writing to text file

Posted 16 January 2013 - 03:36 AM

fso = CreateObject("Scripting.FileSystemObject")
	            inputFile = fso.OpenTextFile(ofd.FileName, 1)
	            str = inputFile.ReadAla
Dim textsplit() As String
textsplit = str.split("v")

For i = 0 to textsplit.Length - 1
textbox1.text = "v" & textsplit(i) & vbnewline
Next


Was This Post Helpful? 1
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3246
  • View blog
  • Posts: 10,887
  • Joined: 12-December 12

Re: New line when writing to text file

Posted 16 January 2013 - 03:37 AM

Sorry, we can't use \escape characters in VB. Try

str = Replace(str, "v", ControlChars.NewLine & "v")

There is also ControlChars.CrLf but this should be the same.
Was This Post Helpful? 1
  • +
  • -

#7 xilith117  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 13-August 11

Re: New line when writing to text file

Posted 16 January 2013 - 12:08 PM

Thanks everyone, my code works now. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1