Shop OBEX P1 Docs P2 Docs Learn Events
Quick Question: Comparing Strings in PBASIC — Parallax Forums

Quick Question: Comparing Strings in PBASIC

hottnikks36hottnikks36 Posts: 8
edited 2006-03-18 06:19 in BASIC Stamp
Hey friendly people.. just a quick question,

I got two byte arrays, each containing some ASCII values (thus some characters), with 0 in the last array index.
Is there a quicker way to compare the two strings then doing

If ((arrayA[noparse][[/noparse]0] = arrayB[noparse][[/noparse]0]) AND (arrayA = arrayB) AND.. etc etc) THEN
'do something
ELSE
'do something else

?

Thanks for your help..

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-17 23:56
    That's the only way you can do it in PBASIC as strings are not really known to the language.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Mike GreenMike Green Posts: 23,101
    edited 2006-03-17 23:58
    How about a loop like:
    i = 0
    doItAgain:
    if arrayA<>arrayB then noMatch
    if arrayA = 0 then allMatched
    i = i + 1
    goto doItAgain
    noMatch: ' mismatch at character position i
    allMatched: ' arrayA and arrayB are equal and the same length
  • Mike GreenMike Green Posts: 23,101
    edited 2006-03-18 00:00
    I got bit by the forum formatting demon ... read {i} as array subscript brackets
    How about a loop like:
    i = 0
    doItAgain:
    if arrayA{i}<>arrayB{i} then noMatch
    if arrayA{i} = 0 then allMatched
    i = i + 1
    goto doItAgain
    noMatch: ' mismatch at character position i
    allMatched: ' arrayA and arrayB are equal and the same length
  • hottnikks36hottnikks36 Posts: 8
    edited 2006-03-18 06:19
    Thanks.. i'll try the loop suggestion..
Sign In or Register to comment.