(I am a VERY basic programmer) :wave:
I have a body of text which needs searching through to find a specific word "Customer" and then save the next line as the CustomerName (CustomerName = <line of text>)
Please help!
Thank you :afrog:
Printable View
(I am a VERY basic programmer) :wave:
I have a body of text which needs searching through to find a specific word "Customer" and then save the next line as the CustomerName (CustomerName = <line of text>)
Please help!
Thank you :afrog:
Hi,
Since you say:-
This implies that the data your are working with has Carriage Return / Line Feed characters in it so in this example I create a string with CRLF characters in it and then use the Split method of the String class to split the Data into lines using the CRLF characters. This can then be iterated through to look for the word "Customer" on a line and, once found, we assign the NEXT line to the myCustomerName variable.Quote:
save the next line as the CustomerName (CustomerName = <line of text>)
Hope that helps.Code:Public Class Form1
Private Const myData As String = _
"Customer ID" & vbCrLf & _
"ABC123" & vbCrLf & _
"Customer" & vbCrLf & _
"ABC Company Ltd" & vbCrLf & _
"Telephone No" & vbCrLf & _
"01245 4578964" & vbCrLf
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myDataLines() As String = myData.Split(CChar(vbCrLf))
Dim myCustomerName As String = String.Empty
For Counter As Integer = 0 To myDataLines.Count - 1
If myDataLines(Counter).Trim = "Customer" Then
myCustomerName = myDataLines(Counter + 1).Trim
End If
Next
MsgBox(myCustomerName)
End Sub
End Class
Cheers,
Ian
Hey Ian,
I'm sorry, I should have given an example of what the code has to search for:
some text
[email protected]
[email protected]
Customer
Mr Blobby
More text etc etc etc blah blah blah
And it would need to extract "Mr Blobby" and save it as "CustomerName"
Thank you very much for the code so far! But I'm guessing there is an easier way to do it?
Thanks,
Conna
Hi,
Sorry, but I do not understand what you are asking for which is different to what I have already posted so far. You have asked to get the Customer, which is on the following line, after finding the word Customer. So what's changed in your second post?
I think you need to expand, in DETAIL, what you are trying to do and what structure you are dealing with.
Cheers,
Ian