Return the first character value of the specified string
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Return the first character value of the specified string
Return the first character value of the specified string.
Currently we have the Asc() function to get the character number. In compiler ASCII mode, the result is the ASCII number, in compiler Unicode mode, the result is the UTF8 number.
However, the function name Asc() is very specific, the name suggests ASCII all the way. I would like to see a separate function to output Unicode character numbers, say: UTF8().
Each function to have dedicated type output regardless of compiler mode.
Currently we have the Asc() function to get the character number. In compiler ASCII mode, the result is the ASCII number, in compiler Unicode mode, the result is the UTF8 number.
However, the function name Asc() is very specific, the name suggests ASCII all the way. I would like to see a separate function to output Unicode character numbers, say: UTF8().
Each function to have dedicated type output regardless of compiler mode.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- langinagel
- Enthusiast
- Posts: 131
- Joined: Fri Jan 28, 2005 11:53 pm
- Location: Germany
- Contact:
Re: Return the first character value of the specified string
Maybe a solution:
But surely as helpful as any other macro-solution.
Greetings
LN
Code: Select all
CompilerIf #PB_Compiler_Unicode
Macro UTF(a.s)
Asc(a.s)
EndMacro
CompilerEndIf
Greetings
LN
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Return the first character value of the specified string
A macro is a good work around. Your macro though ties the compilation to Unicode, which is not wanted. It is possible for an ASCII compiled program to read a Unicode file.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Return the first character value of the specified string
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Return the first character value of the specified string
Read the first post! The answer is Asc(), but that function name does not suggest Unicode.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Return the first character value of the specified string
Haha, I thought you said Asc() is not the answer since it is #PB_Compiler_Unicode dependent?
PeekU() works the same in Ascii/Unicode compile.
PeekU() works the same in Ascii/Unicode compile.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Return the first character value of the specified string
Asc() already returns the unicode character value (not UTF8, as PB doesn't handle UTF8 in native) in unicode. I don't really undestand the question as well 

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Return the first character value of the specified string
Well:
When you have that function in your code, you don't immediately know if it is returning an ASCII number or a Unicode number........the function name Asc() is very specific, the name suggests ASCII all the way.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Return the first character value of the specified string
True. Anyway the function was here to return the first character value, so when we introduced unicode support, it was more or less obvious it would return the first unicode character value, despite of the name.
-
- Addict
- Posts: 1675
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: Return the first character value of the specified string
Maybe Fred should just rename the command to something non-offensive 

Re: Return the first character value of the specified string
> I would like to see a separate function to output Unicode character numbers
So, should every string command have two versions now? One for Ascii and
one for Unicode return values? I don't think that's a good idea to implement.
Perhaps an optional flag can be added for existing commands, but keep them
defaulting to Ascii if the flag is omitted. I don't know. Where is the line drawn?
So, should every string command have two versions now? One for Ascii and
one for Unicode return values? I don't think that's a good idea to implement.
Perhaps an optional flag can be added for existing commands, but keep them
defaulting to Ascii if the flag is omitted. I don't know. Where is the line drawn?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Return the first character value of the specified string
Ah, underlining text, that's another subjectWhere is the line drawn?

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- langinagel
- Enthusiast
- Posts: 131
- Joined: Fri Jan 28, 2005 11:53 pm
- Location: Germany
- Contact:
Re: Return the first character value of the specified string
I second PBs point.
Let's have one ASC() function that provides the correct result in each mode, ASCII or UTF().
The compiler shall take care of this.
ASC() is definitely BASIC standard function, thus widely understandable.
Let's have one ASC() function that provides the correct result in each mode, ASCII or UTF().
The compiler shall take care of this.
ASC() is definitely BASIC standard function, thus widely understandable.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Return the first character value of the specified string
...which is my point. The result could easily be assumed to be ASCII when its Unicode.thus widely understandable
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Return the first character value of the specified string
The behavior of Asc() is documented. The name of the function comes from a timeIdeasVacuum wrote:The result could easily be assumed to be ASCII when its Unicode.
when there was no Unicode (also in PB). VB.NET has functions Asc() and AscW(), in PB it is Asc() for both modes.
If I understand correctly, you just would like a name change, like:
Code: Select all
Macro FirstCharacter(string)
Asc(string)
EndMacro
Debug FirstCharacter("Hello")
