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

Split field

Status
Not open for further replies.

khicon73

MIS
Jan 10, 2008
36
txtValue = "Sugar land, City of |15245|what|8558"
i would like to get the value like:
txtNewValue = "Sugar land, City of"
Please help, thanks.
 
Public Sub test()
Dim splitVals() As String
Dim txtValue As String
Dim newTxtValue As String
txtValue = "Sugar land, City of |15245|what|8558"
splitVals = Split(txtValue, "|")
newTxtValue = splitVals(0)
End Sub

spliVals(1) returns 15245
splitVals(2) returns what
splitVals(3) returns 8558
 



and if you don't care to define separate array variable...
Code:
Public Sub test()
 Dim txtValue As String
 Dim newTxtValue As String
 txtValue = "Sugar land, City of |15245|what|8558"[s]
' splitVals = Split(txtValue, "|")[/s]
 newTxtValue = Split(txtValue, "|")(0)
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
actually if you just want the first one
newTxtValue = Left(txtValue, InStr(txtValue, "|") - 1)

a little less flexible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top