Home > Archive > AWK > November 2007 > removing leading character from left,right a string
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
removing leading character from left,right a string
|
|
| happytoday 2007-11-04, 6:58 pm |
| Hello,
I need to remove a space on the right and left of a string
name =3D " =F4 "
#line 5
for (ix1=3D1;ix1<2;ix1++) getline ;
name=3Dsubstr($0,0,52)
name1=3Dgsub(/^ *| *$/, "",name)
In dos editor the space equal that character according to the font
used : " " That is my code above but useless .
| |
| Ed Morton 2007-11-04, 6:58 pm |
|
On 11/4/2007 3:18 PM, happytoday wrote:
> Hello,
> I need to remove a space on the right and left of a string
> name =3D " =F4 "
> #line 5
> for (ix1=3D1;ix1<2;ix1++) getline ;
> name=3Dsubstr($0,0,52)
Whatever the above is trying to do, using "getline" is almost certainy th=
e wrong
approach. Provide more info if you'd like help on doing it the right way.=
> name1=3Dgsub(/^ *| *$/, "",name)
>=20
> In dos editor the space equal that character according to the font
> used : " " That is my code above but useless .
>=20
gsub() doesn't return a string. You just need to use a character class:
gsub(/^[[:space:]]*|[[:space:]]*$/,"",name)
Regards,
Ed.
|
|
|
|
|