Re: stringtochar function

From: Xin Xi <xxi_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 09 2012 - 10:11:16 MDT

Mary,
I am not trying to get the length in this case. I am trying to get the
"correct" char array converted from the given string, e.g., s="123", I want
get c=(/"1", "2", "3"/) without the NULL char. And I still didnot get it
why there should be a NULL in the end. Thanks.

On Mon, Jul 9, 2012 at 11:45 AM, Mary Haley <haley@ucar.edu> wrote:

> The character you're seeing is a NULL character. This will always be
> appended when you call stringtochar.
>
> I believe the reason for this NULL character is for the case where you
> give it an array of strings. Since each string may be a different length,
> it becomes
> necessary to have something that denotes the actual end of each string
>
> To correctly get the string length, you need to subtract 1:
>
> s = "123456789"
> c = stringtochar(s)
> clen = dimsizes(c) -1
> print("length of c = " + clen)
>
>
> (0) length of c = 9
>
>
> --Mary
>
> On Jul 8, 2012, at 11:27 PM, Xin Xi wrote:
>
> > Hi there,
> > when I use the stringtochar function, the resulting char array has an
> ending element of "0x00". This cause the unmatched dimension size error
> while I tried to assign the char array to a variable (with a dimension of
> the string length). I donot understand how the "0x00" relates to the
> missing value of original string (as detailed on the ncl webpage of the
> stringtochar function). And how can I avoid it? Can someone clarify for me.
> Thanks!
> > Xin
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 9 10:11:37 2012

This archive was generated by hypermail 2.1.8 : Mon Jul 09 2012 - 10:45:32 MDT