Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove all occurences of a character in C string - Example needed

Tags:

c

string

InputString: "I am unwell" "We need to go to the doctor" "How long will it take?".

OutputString: I am unwell We need to go to the doctor How long will it take?

The string needs to cleaned of all occurrences of the char " . I can think of the following approacg

  1. Use, strchr() function finding first occurrence of "
  2. Move all characters in the string left by once position.

Repeat steps 1 and 2 , until strchr() returns a NULL pointer.

I feel this is very inefficient way to approach this problem. I need to know , if there are other methods to achieve this? Pseudo code or actual code will both be appreciated.

like image 208
Eternal Learner Avatar asked Nov 12 '10 05:11

Eternal Learner


People also ask

How do you remove all instances of a string from a string?

Delete All Occurrences of a Character From a String in Python Using the split() Method. We can also use the split() method to remove all the occurrences of a character from a given string. The split() method, when invoked on a string, takes a separator as its input argument.

How do I remove a specific character from a string?

You can also remove a specified character or substring from a string by calling the String. Replace(String, String) method and specifying an empty string (String. Empty) as the replacement.


1 Answers

for (s=d=str;*d=*s;d+=(*s++!='"'));
like image 100
R.. GitHub STOP HELPING ICE Avatar answered Oct 26 '22 10:10

R.. GitHub STOP HELPING ICE