begin
asked on
String content within " "
How to use the content of a string variable within " ".
eg.
int testfound = fd.find("From user argv[1]");
----
simply I need the argument 1 to be substituted there. Is there any escape seq. like that...
any help will be appreciated.
--begin
eg.
int testfound = fd.find("From user argv[1]");
----
simply I need the argument 1 to be substituted there. Is there any escape seq. like that...
any help will be appreciated.
--begin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fd is a string which contains around 50 characters.
--begin
--begin
string U mean is it a character array ? or MFC CString?
pu the declaration of fd here Pl
if str is character array then use
char str[50];
strcpy(str, "From user ");
strcat(str, argv[1]);
fd.find(str);
Hope this helps
char str[50];
strcpy(str, "From user ");
strcat(str, argv[1]);
fd.find(str);
Hope this helps
Just make sure that argv[] is 39 characters long, or less.
..B ekiM
..B ekiM
ASKER
thanks to inpras.
it looks as if you are using the standard library string (good thing too, much less error prone), in which case you can just do:
int pos = fd.find(string("From user ") + argv[1]);
For more complicated substitutions you can use the stringstream class.
int pos = fd.find(string("From user ") + argv[1]);
For more complicated substitutions you can use the stringstream class.
ASKER
thanks jasindarke, it worked pretty well.
--begin
--begin
ASKER
thanks jasondarke, it worked pretty well.
--begin
--begin
unfortunately you accepted someone elses answer, but glad it worked anyway.
ASKER
It seems you have assumed that from my typographical error, that i have accepted someone else's answer, but its not the truth. actually i have once again asked a typical question related to the first one but with a minimal change. hope i have graded your answer. post me if you have any comments. sorry for your feelings..
--begin
--begin
hope U won't mind for this