 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Warren Guest
|
Posted: Wed Jan 28, 2004 2:09 am Post subject: subString replace in a String |
|
|
I am trying to replace some variables with their values
IE
int x1=1,x10=2,x11=3,y7=4,y77=5;
if the string I want to replace the vars is as follows
cos(x11*x10*x1)/tan(y77-y7)
then I would like the string to look as the next line
cos(1*2*3)/(5-4);
what I receive is as follows
cos(11*10*1)/(4-4);
Presently I am using the pos(?) which is not effective so I am wondering
what is the most intelligent way of doing this? I do not mind writing the
code but I don't really want to re-invent the wheel if I don't have to.
Does anyone know of a function that will look for each occurrence of a
substring in a string? That failing is the most effect way to replace the
var name with the var value? There could be X number of var names and each
var name could be in the string X times. I will loop though the string to
complete this but do not know if there are smarter ideas?
Thanks
Warren
|
|
| Back to top |
|
 |
Warren Guest
|
Posted: Wed Jan 28, 2004 2:29 am Post subject: Please Read this Question it is Clearer |
|
|
I am trying to replace some variables with their values
IE
int x1=1,x10=2,x11=3,y7=4,y77=5;
if the string I want to replace the vars is as follows
cos(x11*x10*x1)/tan(y77-y7)
then I would like the string to look as the next line
cos(1*2*3)/(5-4);
what I receive is as follows
cos(11*10*1)/(4-4);
The reason being the search finds the first x1 and replaces that. The first
x1 is really an x11 so the x1 is replaced by the following 1 remains. My x11
is not replaced correctly. Also I do not have authority to demand the var
names start at the highest I.E. x11 and work down to x1 which would be the
simplest solution to my problem.
Presently I am using the pos(?) which is not effective so I am wondering
what is the most intelligent way of doing this? I do not mind writing the
code but I don't really want to re-invent the wheel if I don't have to.
Does anyone know of a function that will look for each occurrence of a
substring in a string? That failing is the most effect way to replace the
var name with the var value? There could be X number of var names and each
var name could be in the string X times. I will loop though the string to
complete this but do not know if there are smarter ideas?
Thanks
Warren
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|