By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,335 Members | 2,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,335 IT Pros & Developers. It's quick & easy.

Character set replacement in a string

P: 10
hi I have a problem.

I have a string with delimiter as '\001'. I have around 50 fields in the string concatenated. I got to replace some of these fields.

Can someone help me in replacing set of characters in the middle of a huge string in C.

I cannot use string functions such as strtok.

please give me an example.
Aug 8 '07 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Traverse the string character by character and append to a temp string. When you reach a field that need replacding, append the replacement to the temp string.

When all the replacements are done, you can copy the temp string back to the original provided the temp string is equal or smaller than the original.

Otherwise, you will need to have the original on th heap and when you are finished, you delete the original string and place the place the address opf the temp string in the pointer used foer the original string.

Or, if you are in C++, just use the string class methods.
Aug 8 '07 #2

P: 10
can you give a example please , my request since i have been whirling around the same since a long time
Aug 8 '07 #3

Expert 10K+
P: 11,448
can you give a example please , my request since i have been whirling around the same since a long time
You do know how to copy char(s) over from one buffer to another, do you?
Comparing a character against your funny delimeter is as simple as *p == '\1'.

kind regards,

Jos
Aug 8 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
Show me your code first.

String handling is a fundmanetal C skill. I can provide assistance but I cannot provide solution code.
Aug 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.