[H-GEN] char inset
Christopher Biggs
chris at stallion.oz.au
Tue May 2 20:59:22 EDT 2000
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Please observe the list's charter. ]
"Grant, Luke" <lgrant at seven.com.au> moved upon the face of the 'Net and spake thusly:
> so what i need is a howto on the following in either bash or perl.
>
> "B43" which is the contents of a string variable must become "B043" and i
> have no idea how i can insert a char into a string in Bash or Perl.....and i
> would rather not have to dust of my old "C" texts cause whilst i know that
> strings are treated as nice simple arrays of char in "C" i haven't coded in
> it for over a year and would rather not start now.
In Perl, as always, TIMTOWTDI.
You can use regexps, pasting of substrings, or you can actually use
the substr() function as an lvalue! (This is seriously twisted.)
# Insert a substring
$foo = "B43";
substr($foo,1,0)="0";
# $foo now holds "B043".
You can replace a substring with a new substring by giving a nonzero
length to the substr lvalue:
# Replace a substring
$foo = "B43";
substr($foo,1,2)="666";
# $foo now holds "B666".
cjb.
--
Christopher Biggs -- chris at stallion.oz.au -- Stallion Technologies Australia.
There's a bug in my mailer that mangles my sig but V guvax V'ir svkrq vg abj.
Uneqyl jbegu qrpbqvat, jnf vg? Rznvy zr "Fhowrpg: fraqctcxrl" sbe zl CTC xrl.
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.
More information about the General
mailing list