[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Gawk 3.04
From: |
Aharon Robbins |
Subject: |
Re: Gawk 3.04 |
Date: |
Sun, 4 Feb 2001 12:18:08 +0200 |
Hi. Thanks for the suggestion. Unfortunately, given the state of the
gawk internals, this is very difficult to do. It also makes the semantics
of tolower/toupper etc much less orthonogal.
This task is relatively easy to do with an awk function, split(), substr(),
and some local variables:
function upcasewords(s, a, n, i, result)
{
n = split(s, a, " ") # split s into array a
for (i = 1; i <= n; i++)
a[i] = toupper(substr(a[i], 1, 1)) substr(a[1], 2)
result = a[1]
for (i = 2; i <= n; i++)
result = result " " a[i]
return result
}
Usage would be:
s = upcasewords("xxx yyy zzz")
Hope that helps,
Arnold
> From: address@hidden
> Date: Thu, 1 Feb 2001 02:00:12 GMT
> Subject: Gawk 3.04
> To: address@hidden
> To: address@hidden
> To: "Gonzalez, Lissette" <address@hidden>
>
> it's been a occuring theme for me to run into this problem which - if solved
> - would add alot of power/functionality to gawk:
>
> s="xxx yyy zzz"
> gsub(/^./, toupper("&"), s)
> gsub(/ ./, toupper("&"), s)
>
> as an over-simplistic example of intending to capitalize the 1st char of all
> words in a sentence. but gawk doesn't seem to allow the matched r.e. to be
> passed to any string returning functions for processing. this would be a
> very powerful enhancement without breaking any existing programs - these
> types of operations are very unwieldy to do in other ways. it also
> has a feel of being "sensible", since "&" should be holding the
> match throughout the middle parameter of g/sub functions. ?
>
> thank you for all your work. :)
>
> Chris.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Gawk 3.04,
Aharon Robbins <=