PDA

View Full Version : parse example ok?



Lionheart008
16-12-2009, 20:31
ok, just a test. perhaps anybody can tell me if this example is ok ? I am wondering only about the line with


songs = ParseCount( america(4), str ) '- result ?

nevertheless this little parse example works fine.


' Empty GUI script created on 12-16-2009 19:03:57 by (ThinAIR)

Function myParse () As Long

Dim str As String
Dim america(10) As String
Dim songs As Long
Dim t As String

str = "I am the best singer songwriter"
songs = Parse( "I,am,a,horse,with,no,name,in,the,desert", america(), "" )

songs = ParseCount( america(4), str ) '- missing result !

t = ParseCount("a,horse,with,no,name", "")

MsgBox 0, "parsecount ok?: " + Str$(t)
MsgBox 0, "5th word of song is: " + america(5)

MsgBox 0, "good night to my friend: " + america(4)
MsgBox 0, "Number of song words: " & UBound(america(1))

MsgBox 0, "yes, ok if it's 1: " + Str$(songs)

End Function

myparse



thanks for reply, frank

Petr Schreiber
16-12-2009, 20:50
Hi Frank,

your example is little bit mysterious.

Array named "America" is filled with values: I,am,a,horse,with,no,name,in,the,desert
The string delimiter "str" is specified as "I am the best singer songwriter".

So


songs = ParseCount( america(4), str )


is equivalent to:


songs = ParseCount( "horse", "I am the best singer songwriter" )


As help file says:


If StringExpression is empty or contains no delimiter character(s), the string is considered to contain exactly one field. In this case, PARSECOUNT returns 1.


"Horse" really does not contain "I am the best singer songwriter", so the returned value is correct according to documentation.

Petr Schreiber
16-12-2009, 20:56
Regarding your help file suggestion,

thanks, but please make a new post in this forum (http://community.thinbasic.com/index.php?board=13.0) dedicated directly to help materials. Otherwise it is very difficult to track all the requests.


Thanks,
Petr

Lionheart008
16-12-2009, 22:32
hello petr, yes, I see, double parsecount with content and values, wasn't necessary and not intended ;)

here cleared version with no more mysterious:


' Empty GUI script created on 12-16-2009 19:03:57 by (ThinAIR)

Function myParse () As Long

Dim str As String
Dim america(10) As String
Dim songs As Long
Dim hello As String
Dim t As String

str = "I am the best singer songwriter"
songs = Parse( "I,am,a,horse,with,no,name,in,the,desert", america(), "" )

songs = ParseCount( america(4), str )
t = ParseCount("a,horse,with,no,name", "")

MsgBox 0, "parsecount ok :) " + Str$(t)
MsgBox 0, "parsecount america :) " + Str$(songs)

MsgBox 0, "5th word of song is: " + america(5)

MsgBox 0, "good night to my friend: " + america(4)
MsgBox 0, "Number of song words: " & UBound(america(1))

End Function

myparse


thanks, good night, frank