Characters in strings

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Characters in strings

Nathan Huesken
Hi,

How do I test in haXe if a character at a specific position is a string is a certain character?
Like this in C++:
if(str[5]==')')
...

I know, there is charCodeAt, but do I need to know the char code of every character I want to test?

Thanks!
Nathan


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Characters in strings

Simon Krajewski
Nathan Huesken schrieb:
> Hi,
>
> How do I test in haXe if a character at a specific position is a string is a certain character?
> Like this in C++:
> if(str[5]==')')
> ...
>
> I know, there is charCodeAt, but do I need to know the char code of every character I want to test?
>  
There's also charAt, see [1].

Regards
Simon

[1] http://haxe.org/api/string

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Characters in strings

Pimm Hogeling
In reply to this post by Nathan Huesken
Hi Nathan,

See http://haxe.org/api/string, there is also a "charAt" method.

"Returns the character at the given position. Returns the empty String if outside of String bounds."

Hope that helps!

On Sun, Aug 2, 2009 at 23:33, Nathan Huesken <[hidden email]> wrote:
Hi,

How do I test in haXe if a character at a specific position is a string is a certain character?
Like this in C++:
if(str[5]==')')
...

I know, there is charCodeAt, but do I need to know the char code of every character I want to test?

Thanks!
Nathan


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Characters in strings

Nicolas Cannasse
In reply to this post by Nathan Huesken
Nathan Huesken a écrit :
> Hi,
>
> How do I test in haXe if a character at a specific position is a string is a certain character?
> Like this in C++:
> if(str[5]==')')
> ...

There's a still undocumented feature for that :

str.charCodeAt(5) == ")".code

the .code is only correct for 1-char constant strings, and is directly
compiled to the charcode integer. This is because there is no "char"
type in haXe, and simple ' quotes are also used for strings.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Characters in strings

Philipp Klose-2
Cool! Are there more of these undocumented features?

Nicolas Cannasse schrieb:

>
> There's a still undocumented feature for that :
>
> str.charCodeAt(5) == ")".code
>
> the .code is only correct for 1-char constant strings, and is directly
> compiled to the charcode integer. This is because there is no "char"
> type in haXe, and simple ' quotes are also used for strings.
>
> Nicolas
>

--
haXe - an open source web programming language
http://haxe.org