slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] how to get a character of a string?


=?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]