Re: extract fields from string using multiple-space delimiter?

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 03 2014 - 13:55:14 MST

Jared,

The str_split function has the property of ignoring consecutive delimiters.
 This can be exploited. Also note the use of a unique substitution
character e.g. "$" which must be chosen carefully to never occur in your
original title strings.

str1 = "Var 1 [units] Var 2 [units] Var 3 [units]"
str2 = str_sub_str (str1, " ", "$")
str3 = str_split (str2, "$")
str4 = str_strip (str3)

;; str3 and str4 are string arrays, not single strings.

print ("str1 = " + str1)
print ("str2 = " + str2)
print ("str3 = " + str_concat ("'" + str3 + "' "))
print ("str4 = " + str_concat ("'" + str4 + "' "))

(0) str1 = Var 1 [units] Var 2 [units] Var 3 [units]
(0) str2 = Var 1 [units]$$ Var 2 [units]$$$$$Var 3 [units]
(0) str3 = 'Var 1 [units]' ' Var 2 [units]' 'Var 3 [units]'
(0) str4 = 'Var 1 [units]' 'Var 2 [units]' 'Var 3 [units]'

Thank you for a fun puzzle on a boring Friday. :-)

--Dave

On Fri, Jan 3, 2014 at 1:23 PM, Jared Lee <jaredlee@ucar.edu> wrote:

> Hi, I'm trying to parse out the fields from the column title line of a
> table, which has the following format:
>
> "Var 1 [units] Var 2 [units] Var 3 [units]"
>
> Each column title is separated by at least two spaces, and never only
> one space. However, to the best of my understanding, the functions
> str_fields_count and str_get_field cannot use multiple consecutive
> spaces (or multiple consecutive anything) as a delimiter, without also
> couting single spaces as a delimiter. Is there any way in NCL to parse
> out fields from a string using double spaces but *NOT* single spaces as
> a delimiter?
>
> Jared
>
> --
> ================
> Dr. Jared A. Lee
> Postdoctoral Research Scientist
> National Center for Atmospheric Research
>
> Phone: 303.497.8485
> Email: jaredlee@ucar.edu
> Web: https://staff.ucar.edu/users/jaredlee
> ================
>
> _______________________________________________
> 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 Fri Jan 03 13:55:25 2014

This archive was generated by hypermail 2.1.8 : Mon Jan 06 2014 - 13:09:53 MST