- Subject: Re: [slang-users] how to get a character of a string?
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Mon, 8 Jan 2007 07:36:41 -0500
=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>how can I get the first character of a string? Think of UTF-8!
Unfortunately there is currently no intrinsic function that returns
this information--- I will add one to the next release. However it is
possible to create such a function for slang 2.0.7 (see below).
>if (substr("hello", 1, 1) == 'h')
Instead of the above, I suggest you use
if (substr("\u{1234}hello", 1, 1) == "\u{1234}") ...
to compare strings instead of characters.
Here is the ugly hack that returns a character (slang 2.0.7 or
greater):
define nth_wchar (str, n)
{
foreach (substr(str, n, 1)) using ("chars");
}
if (nth_wchar ("hello", 1) == 'h') ....
Thanks,
--John
_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html
[2007 date index]
[2007 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]