473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Character set replacement in a string

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
4 1392
weaknessforcats
9,208 Expert Mod 8TB
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
can you give a example please , my request since i have been whirling around the same since a long time
Aug 8 '07 #3
JosAH
11,448 Expert 8TB
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
9,208 Expert Mod 8TB
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

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

Similar topics

3
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
8
by: Dong Ge | last post by:
Hi! I am a beginner of C. I want to delete some characters or a whole line in a text file. I have tried the "fprintf", "fputs", "fwrite", but no one of them can run rightly. In the below...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
3
by: Old Wolf | last post by:
I have two strings of corresponding characters, for example: s1 = "abc" s2 = "XYZ" Is there an algorithm so that whenever a character from S1 occurs in a string, it is replaced by the...
5
by: Jayson Davis | last post by:
Say I have a string read from a configuration file. searchfor <tab> Needle\n\n Where I want to search for the word "Needle" with two linefeeds. Now when I read it from the file, it hasn't...
10
by: pak.andrei | last post by:
Here is my script: from mechanize import * from BeautifulSoup import * import StringIO b = Browser() f = b.open("http://www.translate.ru/text.asp?lang=ru") b.select_form(nr=0) b = "hello...
7
by: Jacek Dziedzic | last post by:
Hello! I am working on a code which features the following macros: #define myname \ ((std::string)(abi::__cxa_demangle(typeid(myself).name(),\ 0,0,&(Framework::demangle_status)))) #define...
4
by: Tim Kelley | last post by:
I am reading a text file with a streamreader. I parse out path and need to use that path in a sql statement. The path is in the file as \\servername\share\folder\filename.txt. When the line is...
7
by: Tom de Neef | last post by:
I need to change one character at a known position in a string. In Pascal I would change the P's character of a string S into 'x' with S:='x'; In JavaScript I come no further than S =...
5
by: shapper | last post by:
Hello, I have a text as follows: "My email is something@something.xyz and I posted this @ 2 am" I need to replace the @ by (AT) bu only the ones that are in email addresses. All other @...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.