|
-
May 16th, 2013, 11:29 AM
#1
Thread Starter
Junior Member
[RESOLVED] Split file & add extra line
Hi guys!
Another small problem, I will try to explain it at best.
I am creating a small program to add a string of text after a type of word has been found. But the string gets placed in a new line above the line instead of under.
What I get:
Code:
.............................
REF: X0.000 Y1078.000 S0.00 ; C:\Salvagnini\syscon\S4_1387/production/20_4_stock_profielen/20_4_stock_profielen_139x3000.S4
REF: X0.000 Y0.000 S0.00
;
; Parts
;
SEQ ; -->> Start unload sequence <<--
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y105.000 U3000.000 V139.000 J1
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y244.000 U3000.000 V139.000 J2
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y383.000 U3000.000 V139.000 J3
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y522.000 U3000.000 V139.000 J4
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y661.000 U3000.000 V139.000 J5
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y800.000 U3000.000 V139.000 J6
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y939.000 U3000.000 V139.000 J7
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y1078.000 U3000.000 V139.000 J8
ESQ ; -->> End unload sequence <<--
;
; Filling scraps
;
PIE: X0.000 Y0.000 U3000.000 V105.000 J-1 DES DWN SCR
..................
What I need:
Code:
REF: X0.000 Y1078.000 S0.00 ; C:\Salvagnini\syscon\S4_1387/production/20_4_stock_profielen/20_4_stock_profielen_139x3000.S4
REF: X0.000 Y0.000 S0.00
;
; Parts
;
SEQ ; -->> Start unload sequence <<--
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y105.000 U3000.000 V139.000 J1
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y244.000 U3000.000 V139.000 J2
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y383.000 U3000.000 V139.000 J3
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y522.000 U3000.000 V139.000 J4
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y661.000 U3000.000 V139.000 J5
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y800.000 U3000.000 V139.000 J6
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y939.000 U3000.000 V139.000 J7
test
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y1078.000 U3000.000 V139.000 J8
test
ESQ ; -->> End unload sequence <<--
;
; Filling scraps
;
PIE: X0.000 Y0.000 U3000.000 V105.000 J-1 DES DWN SCR
My code (short! )
Code:
Dim stackerfile As String
stackerfile = My.Computer.FileSystem.ReadAllText("C:\test.txt")
TextBox1.Text = stackerfile
Dim stackerfilesplit As String = TextBox1.Text
Dim someArray As Array = Split(stackerfilesplit, "PIE: " & Chr(34))
For i As Integer = 0 To someArray.Length - 1
TextBox2.Text = TextBox2.Text & "PIE: " & Chr(34) & (someArray(i).ToString) & "test" & vbNewLine
Next
I tried to change the "test" part before, after, under, etc etc in the last line to get it right, but doesn't work.. I haven't got the "vision" in code like most of you 
Thanks a lot!!!
-
May 16th, 2013, 11:46 AM
#2
Re: Split file & add extra line
It's not really anything to do with code. In this line ...
aaaaPIEbbbbPIEccccPIEdddd
splitting on PIE gives you aaaa, bbbb, cccc, dddd. In your example you only want 'test' to appear after bbbb, cccc, and dddd but your loop starts at 0 and therefore applies it to aaaa as well. You should copy aaaa first, then start your loop from 1 not 0.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 16th, 2013, 12:01 PM
#3
Thread Starter
Junior Member
Re: Split file & add extra line
Thanks.
Damnit, then I should consider some other codes..? Because, I also want that 'test' will be variable depending of what comes after 'PIE: "20......'
so like this:
Code:
SEQ ; -->> Start unload sequence <<--
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y105.000 U3000.000 V139.000 J1
&ONL: stackerpar="ORDER=stockdeuren"
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y244.000 U3000.000 V139.000 J2
&ONL: stackerpar="ORDER=stockdeuren"
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y383.000 U3000.000 V139.000 J3
&ONL: stackerpar="ORDER=stockdeuren"
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y522.000 U3000.000 V139.000 J4
&ONL: stackerpar="ORDER=stockdeuren"
PIE: "20_4_stock_profielen_139x3000.S4" X0.000 Y661.000 U3000.000 V139.000 J5
&ONL: stackerpar="ORDER=stockdeuren"
PIE: "zwee.S4" X0.000 Y800.000 U3000.000 V139.000 J6
&ONL: stackerpar="ORDER=zwee"
PIE: "zwee.S4" X0.000 Y939.000 U3000.000 V139.000 J7
&ONL: stackerpar="ORDER=zwee"
PIE: "zwee.S4" X0.000 Y1078.000 U3000.000 V139.000 J8
&ONL: stackerpar="ORDER=zwee"
ESQ ; -->> End unload sequence <<--
Where the name "zwee.S4" is a fixed name, and "20_4_stock_profielen_139x3000.S4" is variable depending of what day of production.
Just when I thought I was almost there
-
May 16th, 2013, 12:18 PM
#4
Re: Split file & add extra line
That shouldn't affect the logic. You just need to add the appropriate conditional(s) in the loop. If it's only ever z or a number then it's a breeze!
So ... (logic not code)
Split text
Copy split(0)
For i = 1 to split.Length-1
If split(i) starts with "z"
Do one thing
Else
Do another thing
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 16th, 2013, 01:57 PM
#5
Thread Starter
Junior Member
Re: Split file & add extra line
 Originally Posted by dunfiddlin
That shouldn't affect the logic. You just need to add the appropriate conditional(s) in the loop. If it's only ever z or a number then it's a breeze!
So ... (logic not code)
Split text
Copy split(0)
For i = 1 to split.Length-1
If split(i) starts with "z"
Do one thing
Else
Do another thing
I tried, but I still can't get the line that has to be added underneath the existing line.
And the "start with" doensn't work either as in I don't see how I need to converse that to a code..
-
May 16th, 2013, 02:05 PM
#6
Re: Split file & add extra line
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 19th, 2013, 05:41 AM
#7
Thread Starter
Junior Member
Re: Split file & add extra line
 Originally Posted by dunfiddlin
I am sorry, but I am relatively new to vb.. I can't see the wood for the trees, so many methods.. anyone some extra help? 
edit: I mostly get the error: ..... is not a member of 'string'
Last edited by Saffe; May 19th, 2013 at 05:46 AM.
-
May 19th, 2013, 11:43 AM
#8
Re: Split file & add extra line
Well firstly, all of the methods will be useful at some time so it wouldn't hurt to learn and practice with them. Secondly I suggested If split(i) starts with "z". Really shouldn't be that difficult to spot the relevant method given the rather broad hint there!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 19th, 2013, 01:34 PM
#9
Thread Starter
Junior Member
Re: Split file & add extra line
 Originally Posted by dunfiddlin
Well firstly, all of the methods will be useful at some time so it wouldn't hurt to learn and practice with them. Secondly I suggested If split(i) starts with "z". Really shouldn't be that difficult to spot the relevant method given the rather broad hint there!
Thanks. So I adjusted some and now I have:
Code:
Dim stackerfile As String
stackerfile = My.Computer.FileSystem.ReadAllText("C:\test.txt")
TextBox1.Text = stackerfile
Dim stackerfilesplit As String = TextBox1.Text
Dim someArray As Array = Split(stackerfilesplit, "0 J1")
For i As Integer = 0 To someArray.Length - 1
Dim code As String
If someArray.ToString.StartsWith("PIE: ") Then
code = "zwe"
Else
code = "profiel"
End If
TextBox2.Text = TextBox2.Text & (someArray(i).ToString) & "0 J1" & vbNewLine & code
Next
But the "If someArray.Tostring.startsWith("PIE: ")" doesn't seems to work, though I don't get any errors or so.. Is it the problem that array doesn't work with string?
greets and thanks a lot!!
-
May 19th, 2013, 07:08 PM
#10
Re: Split file & add extra line
How can you convert an array (multiple strings) to a single string? Are you wanting to concatenate the values of each string into one?
Change this line:
Code:
Dim someArray As Array
To this:
Code:
Dim someArray As String()
Also, maybe you want to index the element of that array??
Code:
If someArray(i).Tostring.startsWith("PIE: ")
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 20th, 2013, 05:21 AM
#11
Thread Starter
Junior Member
Re: Split file & add extra line
 Originally Posted by AceInfinity
How can you convert an array (multiple strings) to a single string? Are you wanting to concatenate the values of each string into one?
Change this line:
Code:
Dim someArray As Array
To this:
Code:
Dim someArray As String()
Also, maybe you want to index the element of that array??
Code:
If someArray(i).Tostring.startsWith("PIE: ")
I tried, without succes. But I noticed, is when I change the startswith part "PIE: " of "If someArray(i).Tostring.startsWith("PIE: ")" to the first word of textbox1, it does work. So the code doesn't look at the beginning of the line, but the beginning of the whole text..?
-
May 20th, 2013, 07:14 AM
#12
Thread Starter
Junior Member
Re: Split file & add extra line
Ok, so I dropped the whole split code and tried sometring else. And it works fine, just as I wanted. I will put my code here so other people could use it.
Code:
Dim streamReader As New System.IO.StreamReader("C:\test.txt")
Do Until streamReader.EndOfStream
Dim line As String = streamReader.ReadLine()
TextBox1.Text = TextBox1.Text & vbNewLine & line
If line.StartsWith("something1") Then
TextBox1.Text = TextBox1.Text & vbNewLine & "textsomething1"
End If
If line.StartsWith("something2") Then
TextBox1.Text = TextBox1.Text & vbNewLine & "textsomething2"
End If
Loop
streamReader.Close()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|