中去掉一个字符的所有出现在C字符串 - 例如需要 [英] remove all occurences of a character in C string - Example needed
问题描述
InputString:我不舒服,我们需要去看医生
这将需要多长时间?
OutputString:我不舒服,我们需要去看医生它需要多长时间
该字符串需要清理炭的所有出现的。我能想到以下approacg的
- 使用,和strchr()函数查找第一次出现
- 将所有字符由一次位置离开的字符串中。
重复步骤1和2,直到和strchr()返回NULL指针。
我觉得这是解决这个问题非常低效的方式。我需要知道,如果有其他的方法来实现这一目标?伪code或实际code都将是AP preciated。
为(S = D = str中; * D = * S;!D + =(* S + =' ));
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
- Use, strchr() function finding first occurrence of
"
- 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.
for (s=d=str;*d=*s;d+=(*s++!='"'));
这篇关于中去掉一个字符的所有出现在C字符串 - 例如需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!