Jump to content

Text string problems with character that disappears and is replaced by an ASCII control character


Recommended Posts

Hi, I am having problems with some text strings taken from some html pages.

for example in the html there is this portion of text "...sacchi da kg. 25. gyproc..." but it returns an error with the API call I make.

If I paste the string into the editor I notice that the character '2' is no longer there and instead the control character "DC2" appears (see image below).

I discovered by pasting the text into the editor that the problem is a character in the string, exactly the '2' that the editor shows me as DC2 (device control 2), see image below.


I tried with a loop to check each character by checking AscW and Unicode and indeed the character '2' of 'kg. 25' disappears, replaced precisely by DC2.

----- $aWords[1]: [s] [AscW:115] Unicode code: U+000073
----- $aWords[2]: [a] [AscW:97] Unicode code: U+000061
----- $aWords[3]: [c] [AscW:99] Unicode code: U+000063
----- $aWords[4]: [c] [AscW:99] Unicode code: U+000063
----- $aWords[5]: [h] [AscW:104] Unicode code: U+000068
----- $aWords[6]: [i] [AscW:105] Unicode code: U+000069
----- $aWords[7]: [ ] [AscW:32] Unicode code: U+000020
----- $aWords[8]: [d] [AscW:100] Unicode code: U+000064
----- $aWords[9]: [a] [AscW:97] Unicode code: U+000061
----- $aWords[10]: [ ] [AscW:32] Unicode code: U+000020
----- $aWords[11]: [k] [AscW:107] Unicode code: U+00006B
----- $aWords[12]: [g] [AscW:103] Unicode code: U+000067
----- $aWords[13]: [.] [AscW:46] Unicode code: U+00002E
----- $aWords[14]: [ ] [AscW:32] Unicode code: U+000020
----- $aWords[15]: [] [AscW:18] Unicode code: U+000012  <---------------
----- $aWords[16]: [5] [AscW:53] Unicode code: U+000035
----- $aWords[17]: [.] [AscW:46] Unicode code: U+00002E
----- $aWords[18]: [ ] [AscW:32] Unicode code: U+000020
----- $aWords[19]: [g] [AscW:103] Unicode code: U+000067
----- $aWords[20]: [y] [AscW:121] Unicode code: U+000079
----- $aWords[21]: [p] [AscW:112] Unicode code: U+000070
----- $aWords[22]: [r] [AscW:114] Unicode code: U+000072
----- $aWords[23]: [o] [AscW:111] Unicode code: U+00006F
----- $aWords[24]: [c] [AscW:99] Unicode code: U+000063

How is this possible?

what happens to the two? and how is this problem solved?

This is an example , the problem also happens with other characters.





Edited by cdeb
Link to comment
Share on other sites

Most probably, the origin string is UTF8. AutoIt native strings use UCS2, a subset of Unicode limited to the BMP. The bold part of your post doesn't even match the char by char dump below.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

at some point it happens to me too and I just replaced them. try it if it works for you

Func CharReplace($String) ; Replace %xx escapes
    Local $iPosition, $iChar, $NewString

    $NewString = $String
    While 1
        $iPosition = StringInStr($NewString, "%")
        If $iPosition > 0 Then
            $iChar = StringMid($NewString, $iPosition + 1, 2)
            ConsoleWrite(" -- %" & $iChar & "=" & Chr(Dec($iChar)))
            $NewString = StringReplace($NewString, "%" & $iChar, Chr(Dec($iChar)))

    ConsoleWrite("" & @CRLF)

    $NewString = StringReplace($NewString, "�", "-")
    Return $NewString

EndFunc   ;==>CharReplace


I know that I know nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...