Prev: Combobox Showing Right Justified
Next: Can't make exe
From: Bill Betournay on 19 Mar 2010 18:14 I've spent half the day today on try to figure out how to parse this string. Here it is I have a string like this: "1 1.1 1.2 1.3 1.4 1.5 1.6" and sometimes that string may have more that one carriage return like I have in my example between 1 & 1.1 What I need is to separate out each number like 1 1.1 1.2 1.3 1.4 1.5 1.6 I've been googling and sifting through help files looking for a way to parse it out but I can't seem to find any. This has to be an easy task and I sure would appreciate any help at all. Thank you Bill
From: Mike Williams on 19 Mar 2010 18:41 "Bill Betournay" <bill(a)REMOVEdatapacks.com> wrote in message news:eGFx9F7xKHA.2012(a)TK2MSFTNGP04.phx.gbl... > I've spent half the day today on try to figure out how > to parse this string. Here it is. I have a string like this: > "1 1.1 1.2 1.3 1.4 1.5 1.6" and sometimes that string > may have more that one carriage return like I have in > my example between 1 & 1.1 You mean more than one space? > What I need is to separate out each number like 1 > 1.1 > 1.2 . . etc There are loads of different ways of doing it. Here's one way that will parse it no matter how many spaces there are between the individual values: Private Sub Command1_Click() Dim s1 As String, s2() As String, n As Long s1 = "1 1.1 1.2 1.3 1.4 1.5 1.6" Do n = Len(s1) s1 = Replace(s1, " ", " ") Loop Until Len(s1) = n s2 = Split(s1, " ") ' display the result: For n = LBound(s2) To UBound(s2) Print n, s2(n) Next n End Sub Mike
From: dpb on 19 Mar 2010 18:44 Bill Betournay wrote: .... > I have a string like this: "1 1.1 1.2 1.3 1.4 1.5 1.6" and sometimes that > string may have more that one carriage return like I have in my example > between 1 & 1.1 You don't show cr/lf pairs, only a couple spaces in your example. You _really_ have a string w/ embedded crlf characters separating entries? Even if do, idx = instr(DataString, vbCrLf) will return position of next match if exists, 0 if not. Put in a loop until 0 or reach end of string, converting each subsection of nonzero length on each pass. I'm stuck w/ VB5 so don't recall if the VB6 Split() function would handle this or not otomh... --
From: Mike Williams on 19 Mar 2010 18:58 "Bill Betournay" <bill(a)REMOVEdatapacks.com> wrote in message news:eGFx9F7xKHA.2012(a)TK2MSFTNGP04.phx.gbl... > I've spent half the day today on try to figure out > how to parse this string . . . By the way, in the code I just posted there are the lines: s1 = Replace(s1, " ", " ") Loop Until Len(s1) = n s2 = Split(s1, " ") In the first of those three lines there are two spaces in the first set of quotes and one space in the second set, and in the third of those three lines there is one space in the set of quotes. So if you are typing it into your code rather than pasting it in then make sure you type it correctly. Otherwise, if you wish, you can change those three lines to the following so that the code is more easily readable: s1 = Replace(s1, Space$(2), Space$(1)) Loop Until Len(s1) = n s2 = Split(s1, Space$(1)) Note that in the array in which the results are placed the individual items are Strings, so in the rest of your code you might like to use Csng or some other suitable function to convert them into Singles or whatever you are using. Mike
From: Nobody on 19 Mar 2010 20:15
What version of VB are you using? |