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

Text string manipulation?

Status
Not open for further replies.

Pistol34

MIS
Nov 17, 1999
55
US
I am going to read in a text string from a file. The string is a little different than I am use to. Here is a sample:

(("IPBIONO" "T" "OPER_MFG" "A-B" "T" 0 0 ("" "GUARD" "GREEN" "1NO-1NC" "" "") "F") ("IPBLT"
"F" "F" "F" "F" 0 "F" ("72=G")))

I figure I will break it down by the spaces in between each ending quoute and beginning quote. I will then DIM an array and feed in the text. The opening ('s tell me how many devices I must read. Can I read in the string until the character <> ( then return a count? I am a little unsure of what the code would be like to break down the string. Any Ideas are much appreciated.

Thanks
 
Check out the split() function. It will split up string and put in a array just like you want. Don't know what will take to get it to work with all those quotation marks in your string.
David Paulson


 
What is your desired array after processing this string??

Give me an example of the results and I may be able to give you the code to do it.
(EG arr(0) = IPBIONO
arr(1) = T
....)

Simon
 
Simon,
The only trick is to get everything seperated with spaces into it's own index in the array. I think you pretty much hit it right on the head in with your first post. Move left to right in the string filling in the array. One proble might be spaces between quotes EG &quot;IBPI ONO&quot;

I have one other problem, I am writing this to help out a friend with a larger program and he was a little light on details. Do you think you could give me a couple of different solutions? I greatly appreciate you help!

Thanks alot,

Pete

 
The following code puts everything in quotes into an array:

Dim FileNum As Long
Dim arr() As String
Dim i As Long
Dim lStringLength As Long
Dim sLine As String
Dim sArrayEntry As String
Dim bInString As Boolean
Dim lElements As Long

FileNum = FreeFile
Open &quot;c:\aa\aa.txt&quot; For Input As #FileNum

Line Input #FileNum, sLine
lStringLength = Len(sLine)

For i = 1 To lStringLength
If Mid(sLine, i, 1) = Chr(34) Then
If bInString = True Then
lElements = lElements + 1
ReDim Preserve arr(lElements)
arr(lElements - 1) = sArrayEntry
sArrayEntry = &quot;&quot;
bInString = False
Else
bInString = True
End If
Else
If bInString = True Then
sArrayEntry = sArrayEntry & Mid(sLine, i, 1)
End If
End If
Next i

Close #FileNum


The problem with this is that it misses tha numbers (they are not in quotes!!).

Without seeing exactly how you want the string given as an example, I cannot put any code in to handle unwanted characters like the brackets at the beginning of the string???

Simon
 
Thank you very much. I will see what I can do about the numbers.

Thanks Again,

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top