[Thread Prev][Thread Next][Index]

Re: [ferret_users] Is there any string function to divide string into pieces by character



Thank you.


On Sun, Aug 25, 2013 at 9:19 AM, William S. Kessler <william.s.kessler@xxxxxxxx> wrote:
I really suggest that you not cc Ansley on questions.

First, she gets the messages on the list just like anyone else. This list is for Ferret users to answer questions *for each other*. It is not a support site where one expects "service" from site managers (and usually pays for this privilege). Ansley is a Ferret developer, busy improving Ferret for all of us. She very nicely answers a lot of questions, but please do not assume that she will drop what she's doing to answer your question, as implied by a specific cc to her. Ask the list!

I think you should be able to do this using the SUBSTRING command, probably in a REPEAT loop. It looks kind of ugly.

How about:

let junk={`substring(test,1,1)`,`substring(test,2,1)`,`substring(test,3,1)`,....}

But if you want to list any single element of a string, that is easily done with SUBSTRING:

list substring(test,4,1)

Maybe this would be best done in a "subroutine" (a script called from the command line or another script). The subroutine would consist of the following line:

list substing(test,$1,1)

Where $1 is an argument passed to the script. Or all 3 arguments to substring could be passed, in which case the script (called substring_script.jnl) would be:

list substring($1,$2,$3)

called like:

go substring_script test 4 1

Billy K

On Aug 24, 2013, at 7:24 PM, Akshay Hegde wrote:

> Hi ! all
> I am searching whether any string function available in ferret, to divide string into pieces by character
>
> for example
>
> yes? let test = {"0123456789 "} ! Being test variable
> yes? list test
>              VARIABLE : {"0123456789 "}
>              X        : 1
>         "0123456789 "
> yes? list strlen(test) ! list the length of string
>              VARIABLE : STRLEN(TEST)
>              X        : 1
>           11.00
>
> I want to split string by character so that if I list them, I should get single character in each index
> list /i=1:11 dummy
> 1   / 1:"0"
>
> 2   / 2:"1"
> 3   / 3:"2"
> 4   / 4:"4"
> 5   / 5:"5"
> 6   / 6:"6"
> 7   / 7:"7"
> 8   / 8:"8"
> 9   / 9:"9"
> 10  /10:"10"
>
> 11  /11:" "
>
>
> please let me know if any....
>
>
> Regards,
> Akshay Hegde
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
William S. Kessler
NOAA / Pacific Marine Environmental Laboratory
7600 Sand Point Way NE
Seattle WA 98115 USA

william.s.kessler@xxxxxxxx
Tel: 206-526-6221
Fax: 206-526-6744
Web: http://faculty.washington.edu/kessler/



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement