Beijer Electronics (formerly QSI Corporation)
http://www.qsiforums.com/

Character Strings
http://www.qsiforums.com/viewtopic.php?f=6&t=4470
Page 1 of 1

Author:  kkwon [ Tue Jul 03, 2012 11:46 am ]
Post subject:  Character Strings

Hi,
Have a byte stream with some character strings being received by the A12 panel using Qlarity 2.63.
The end of the string is marked by a NULL, 0 and is stored in aArray[] (dim as BYTE)
Problem I have is with terminating the string when displayed via a LabelV2 object.
When assigning Label.value = aArray the value shown is
"password" followed 6 characters that look like square boxes. How do I get rid of the 6 square boxes that follow the string?

Have tried Trim, _CharStrToStr, but no luck.

Author:  Jeremy [ Tue Jul 03, 2012 11:52 am ]
Post subject:  Re: Character Strings

In Qlarity, NUL characters in a string are perfectly permissible. If you are receiving such a string from an external source, you must manually find the NUL and terminate. Here is an example.

Code:
dim pos as integer
pos = Find(aArray, 0, -1, "\0")
if pos >= 0 then
    redim(aArray, pos)
endif

Author:  kkwon [ Wed Jul 04, 2012 2:49 pm ]
Post subject:  Re: Character Strings

Hi,

Tried the following:
dim sPassword as charstr
init sPassword := ""

func ProcessSetPasswordCommand(data[] as byte, nLen as integer)

dim index, i, pos as integer
init index := 3
init i := 0
dim arr[15] as byte
dim arr2[15] as byte

' copy the password string with NUL termination.
for i=0 to 10 step 1
arr[i] = data[index+i]
next

pos = Find(arr, 0, -1, "\\0")

if (pos >= 0) then
redim(arr, pos)
endif

sPassword = charstr(arr)


' DEBUG
Label_DebugMsg.value = sPassword

return

endfunc 'ProcessSetPasswordCommand

Label_DebugMsg.value will show "helloworld" with 6 square box symbols following. Can't figure out
how to get rid of the junk after "helloworld"

Author:  Jeremy [ Thu Jul 05, 2012 6:53 am ]
Post subject:  Re: Character Strings

For debugging purposes, try doing this:

' DEBUG
Label_DebugMsg.value = str(sPassword)

This will let you see exactly what characters are associated with each index of that array. Perhaps it is not a NUL in the array, but some other non-printable character (the box is the "replacement" character, and displayed whenever a character exists in the string that the font doesn't define).

Also, should you be using nLen somewhere?

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/