Android Question How to work with mixed ascii and hex string

billyrudi

Active Member
Licensed User
Longtime User
Hi,
how i can remove all non printable chars from a string to obltain only readible chars?
the string came from a socket stream


regards Paolo
 

sorex

Expert
Licensed User
Longtime User
maybe there's another way but this might work for you

B4X:
    Dim t As String="ÂPÊrÎiÔn"& CRLF &"ÛtŶ"& TAB &"aĈbĜlĤeĴ ŜoŴnẐlẐy"
    Dim po As String
    Dim c As Int   
    For x=0 To t.Length-1       
        c=Asc(t.CharAt(x))
        If c>0x20 And c<0x80 Then po=po & Chr(c)
    Next
    Log(po)

Waiting for debugger to connect...
Program started.
Printableonly
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You should edit the thread and change the title to a relevant title.

2. If you are working with a limited range of characters then it is possible to implement a simple check like @sorex did (though it is better to use StringBuilder). Catching all the possible non-printable characters will be more difficult.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…