BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

subString replace in a String

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Non-Technical)
View previous topic :: View next topic  
Author Message
Warren
Guest





PostPosted: Wed Jan 28, 2004 2:09 am    Post subject: subString replace in a String Reply with quote



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





PostPosted: Wed Jan 28, 2004 2:29 am    Post subject: Please Read this Question it is Clearer Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Non-Technical) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.