Re: string plus string

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sat Mar 19 2011 - 09:29:03 MDT

x = asciiread("....", -1, "string")

nx = dimsizes(x)
do n=0,nx-1
    nf = str_fields_count(x(n), " ")
    if (nf.eq.1) then
        ss = str_split(x(n)," ")
    else
        aa = str_split(x(n)," ")
        ss = aa(0)+" "+aa(1)
    end if
     print(""+ss)
end do

or

ss = new(nx, "string", "No_FillValue")
do n=0,nx-1
    nf = str_fields_count(x(n), " ")
    if (nf.eq.1) then
        ss(n) = str_split(x(n)," ")
    else
        aa = str_split(x(n)," ")
        ss(n) = aa(0)+" "+aa(1)
    end if
end do

print(""+ss)

On 3/18/11 4:59 PM, Mark Chan wrote:
> NCL users,
>
>
> If "x" is a string array like this:
>
> aaa1 aaa2
> bbb1
> ccc1 ccc2
> ddd1
> eee1
>
> I want to make a NCL script as:
>
> s1 = str_get_field(x(1:),1," ")
> s2 = str_get_field(x(1:),2," ")
> if (s2.ne."null") then ;------------------how to judge "s2" here
> ss =s1+" "+s2
> else
> ss=s1
> end if
>
> The aim is plus "s1" and "s2" with a space between only if "s2" has value.
> Otherwise the string "ss" would have extra space (e.g. ss=s1+" "), which damage
> the variable name.
> Can any one help!
>
> Thanks very much.
>
> Mark
>
>
>
>
> _______________________________________________
> 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 Sat Mar 19 09:29:09 2011

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2011 - 16:15:59 MDT