Manipulating strings to remove certain words? Quick Question

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Manipulating strings to remove certain words? Quick Question

Post by sg57 »

I have been wanting to know, how do you/I manipulate / edit a string/buffer to remove certain words? EX:

Code: Select all

BEFORE:
sprintf(buffer, "You're weird and this is an example.");
printf(buffer);

AFTER:
sprintf(buffer, "weird example");
printf(buffer);
What was removed was:

-You're
-and
-this
-is
-an

I have looked into the token string manipulative and that only removes certain characters, not words.

Also, if its easier, Im just in need of removing about 50 characters/words at the beginning and after of the string. Later I will need to substitute a series of characters as someting else, but I can make a strcpy and if they match, replace it with what I need. Please help, or atleast point me to a place that has EVERYTHING about strings and how to change/manipulate them. I know Im asking somewhat alot, but itd really help if i got an answer or some explanation of what to do. Thanks.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

trying to code a 'nanny'?
player types: "stupid fuck!"
game sends: "stupid $%&$"

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
fish
Posts: 25
Joined: Wed Feb 08, 2006 5:12 am

Re: Manipulating strings to remove certain words? Quick Ques

Post by fish »

sg57 wrote:I have been wanting to know, how do you/I manipulate / edit a string/buffer to remove certain words? EX:

Code: Select all

BEFORE:
sprintf(buffer, "You're weird and this is an example.");
printf(buffer);

AFTER:
sprintf(buffer, "weird example");
printf(buffer);
What was removed was:

-You're
-and
-this
-is
-an

I have looked into the token string manipulative and that only removes certain characters, not words.

Also, if its easier, Im just in need of removing about 50 characters/words at the beginning and after of the string. Later I will need to substitute a series of characters as someting else, but I can make a strcpy and if they match, replace it with what I need. Please help, or atleast point me to a place that has EVERYTHING about strings and how to change/manipulate them. I know Im asking somewhat alot, but itd really help if i got an answer or some explanation of what to do. Thanks.
strtok to the next word (ie char after a space), store the position of this char
strtok to the next word (ie char after a space), store this position too.
compare the chars between these two with each word of the same length in your 'compare' list.
sprintf/memcpy the first chunk (0-char1)(ie. OK words) to another buffer.
repeat till end of string.

There might be libraries that can do this though:p
have you tried looking at <string.h>, if it's been built for the PSP?
str
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

I have looked in all of the libraries. So far I have gotten from an 'expert' at go4g.com that I have to parse the string then simply make a string compare call and if < matches >, then remove the <amsdf> word. I still do not understand your postas to what to do, but Im re reading it......
Post Reply