![](sad.gif)
Scanning strings
How do I scan a string to eliminate a character or remplace it
(And NO, I can''t acces MSDN cuz my CD drive is broken
)
![](sad.gif)
(you can find me on IRC : #opengl on undernet)
Wow, sucks to be you with a broken cd drive.
j/k...
Should be something like... (if you''re only scanning for single characters and not a sequence of them...)
And, no, the Hello should not be Sello, because it''s scanning for lowercase ''h''... I think that should do it... Try it out.![](smile.gif)
S.
![](tongue.gif)
Should be something like... (if you''re only scanning for single characters and not a sequence of them...)
|
And, no, the Hello should not be Sello, because it''s scanning for lowercase ''h''... I think that should do it... Try it out.
![](smile.gif)
S.
Just to make a point that everything can be done diferent ways (or just to get a reason to post a reply
you could with the same effect use a switch/case statement (I prefer doing so in cases like this because the code is easier to read)
![](smile.gif)
int len = strlen(Mystring); //faster to precalculate for(int i=0; i < len; i++){ switch(Mystring) { case ''h'' : Mystring = ''s'';<br> break;<br> case ''y'' :<br> Mystring = ''d'';<br> break;<br> case ''p'' :<br> for(j = i; j < len - 1; j++)<br> Mystring[j] = Mystring[j + 1];<br> Mystring[len - 1] = ''\0'';<br> break;<br> } // switch<br>} // for i<br></pre><br><br>So there… :-) </i>
Sorry Strylinys, but your code out puts "Hello, I am a sapd string" And as far as I know I haven''t ever seen a sapd string walking around here--how about up in Canada
![](tongue.gif)
the problem with replacing words in a string is that if the length of the string grows you have to make sure you allocate more memory for it, or you'll run into an overflow error or lose some of your string.
you might try something like this
Edited by - ogapo on October 21, 2000 4:48:01 PM
you might try something like this
|
Edited by - ogapo on October 21, 2000 4:48:01 PM
Brought to you by: [email=ogapo@ithink.net]O.G.A.P.O.[/email] +----------------------------------------+| Surgeon General's Warning - || OGAPO can cause serious mental damage || if taken in large doses. |+----------------------------------------+/* Never underestimate the power of stupid people in large groups */
What?! You''ve never seen a sapd string??!??!!? Wow, you''re missing out... ![](tongue.gif)
No, seriously.. That was just off of the top of my head (not too good these days.
)
It should have this in there (I think you can figure out where...)
There, NOW it''s a sad string... But it''s much more interesting when we are able to examine the sapd string in its natural environment.![](smile.gif)
S.
![](tongue.gif)
No, seriously.. That was just off of the top of my head (not too good these days.
![](smile.gif)
It should have this in there (I think you can figure out where...)
|
There, NOW it''s a sad string... But it''s much more interesting when we are able to examine the sapd string in its natural environment.
![](smile.gif)
S.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement