Here is a procedure with both null and no null. Here are my tests:
returns TRUE when
1. both same length, same contents, no null char
2. both same length & same contents up to same position mid null char.
3. different lengths & same contents up to same position mid null
char.
4. diff length, null on larger string one byte after end of first
string.
returns FALSE when
1. different lengths, no null char
2. different lengths, null char in different mid positions.
2. same lengths, null char in different mid positions.
--------------------------------------------------------------------------------
-- compare two strings to see if they are the same. not case
dependant.
-- strings can optionally be terminated with a null character.
--------------------------------------------------------------------------------
function string_compare(byte in string1[], byte in string2[]) return
bit is
var byte step, s1, s2
var bit check = TRUE
step = 0
forever loop
s1 = string1[step]
s2 = string2[step]
-- check for null character
if (s1 == ASCII_NULL) | (s2 == ASCII_NULL) then
if (s1 + s2) == 0 then
return TRUE
else
return FALSE
end if
end if
-- convert both to lower case
char_lower(s1)
char_lower(s2)
-- check if they are different
if !(s1 == s2) then
return FALSE
end if
if count(string1) == count(string2) then
if step == (count(string1) - 1) then
return TRUE
end if
elsif step == (count(string1) - 1) then
if string2[step + 1] == ASCII_NULL then
return TRUE
else
return FALSE
end if
elsif step == (count(string1) - 1) then
if string1[step + 1] == ASCII_NULL then
return TRUE
else
return FALSE
end if
end if
step = step + 1
end loop
end function
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.