I am trying to collect equivalent statements in various languages.
I am now dealing with substring assignment.
Let us assume that string="abcd", value="AB", i=2, j=3 (I won't
scandalize if in your favourite language it is i=1 j=2 :=). Nor if one
has to use n=j-i+1 (length("AB")).
I want an assignment which returns string="aABd"
I started from Fortran string(i:j)=value
I came out with the examples below, but cannot find a satisfactory one
for C using standard library functions.
IDL: strput,string,value,i
Java: string=string.substring(0,i)+value+string.substrin g(j+1) ;
or using string buffers
StringBuffer sb = new StringBuffer(string) ;
sb.replace(i,j+1,value) ;
awk: string=substr(string,1,i-1) value substr(a,j+1)
mysql: set @string:=insert(@string,@i,@n,@value)
Postscript: string i value putinterval /string exch def
I even have csh
@ i=$i-1
@ j=$j+1
set string=`echo $string | cut -c-$i`$value`echo $string | cut -c$j-`
But what about C ?
I can find an hardcoded solution for a character array
char a[5]="abcd" ;
a[1]='A';
a[2]='B';
which means I can possibly write some for loop
But what if I want a (or string) to be a "standard" string i.e. a
char *a ?
Please note followup to clf
--
----------------------------------------------------------------------
is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.