Is Character

RichardBernard

Member
Licensed User
Longtime User
Hi guys,

I'm trying to write a function that checks to see if a character is somewhere within the ASCII table.

B4X:
Sub IsCharacter (Character As Char) As Boolean
   If Conv.CharsToBytes(Character) > 0x20 AND Conv.CharsToBytes(Character) < 0x7E Then
      Return True
   Else
      Return False
   End If
End Sub

Can you help me understand what is the compiler barking at?

B4X:
Parsing code.                           0.01
Compiling code.                         Error
Error compiling program.
Error description: Cannot cast type: {Type=Char,Rank=0} to: {Type=Char,Rank=1}
Occurred on line: 410
If Conv.CharsToBytes(Character) > 0x20 AND Conv.CharsToBytes(Character) < 0x7E Then
Word: character


I would appreciate any help!
R
 

stevel05

Expert
Licensed User
Longtime User
From the docs:

B4X:
CharsToBytes (vals() As Char) As Byte()

CharstoBytes expects and returns an array.
 
Upvote 0

RichardBernard

Member
Licensed User
Longtime User
Am I making this complicated, is there an easier way to do what I'm trying to do?

Do you know of any library function that would return one byte for the purpose of that comparison?

Thanks for any the hint!
R
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try:

B4X:
Asc (Char As Char) As Int

Returns an int, but the value is the same.
B4X:
Log(Asc(" ") = 0x20)
still works
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I usually just search the forum.

There is a lot of accessible info in the Wiki or in the Documentation option in the main menubar of the forum.

and also via an andriod device here.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
where are the "docs" that you mentioned??
The help is in included each library xml file. The online help is extracted from these xml files but is not always up to date. You can view it from your local library files, which should be the most up to date, using

ObjectBrowser

or

B4AHelpViewer
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
I'm trying to write a function that checks to see if a character is somewhere within the ASCII table.

from what I read, I understand you want to know if "ABCDEF" CONTAINS "C",.. is that right?
 
Upvote 0

RichardBernard

Member
Licensed User
Longtime User
from what I read, I understand you want to know if "ABCDEF" CONTAINS "C",.. is that right?

Almost, you know how we have the IsNumber(Text As String) in the library? Well I was trying to write a Sub that would search to see if a character passed to it lies withing 0x20 and 0x7E on the ASCII table; which Stevel05's solution addressed it.

R
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
may also consider this pseudo code

for I = FirstCharValue to LastCharValue
StringLine = StringLine & chr(I)
next

then use the instring function to see if your char is there!
 
Last edited:
Upvote 0
Top