Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Indexed ass...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 2177 of 2236
Post > Topic >>

Re: Indexed assignment

by Joel Reicher <joel@[EMAIL PROTECTED] > Mar 4, 2008 at 02:55 AM

Joel Reicher <joel@[EMAIL PROTECTED]
> writes:

> s = sprintf("%s%s%s", substr(s, 1, pos-1), insert, substr(s,
pos+length(insert)))
> 
> And in your example, s="123456789", pos=3, and insert="abc".

Sorry, I just realised that's more C-like than it needs to be. A more
awkish expression would probably be

s = substr(s, 1, pos-1) insert substr(s, pos+length(insert))

In other words, string concatenation is native in awk and there's no
need to use sprintf() the way I did originally.

Cheers,

        - Joel




 6 Posts in Topic:
Indexed assignment
bernhard.strohmeier@[EMAI  2008-03-03 02:42:46 
Re: Indexed assignment
gazelle@[EMAIL PROTECTED]  2008-03-03 11:34:00 
Re: Indexed assignment
Ed Morton <morton@[EMA  2008-03-03 06:14:11 
Re: Indexed assignment
Joel Reicher <joel@[EM  2008-03-03 12:32:32 
Re: Indexed assignment
Joel Reicher <joel@[EM  2008-03-04 02:55:25 
Re: Indexed assignment
bernhard.strohmeier@[EMAI  2008-03-03 05:23:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 1:30:16 CDT 2008.