LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2005, 05:08 PM   #1
AquamaN
Member
 
Registered: Oct 2002
Location: Ohio, USA
Distribution: OS X 10.4.8, Ubuntu 6.10
Posts: 146

Rep: Reputation: 15
string question


Ok, so I am trying to get all the length of words in a file, but some words are special like "copy-cat" and I need to break them up into just "copy" and "cat" and it's been ages since I've worked with strings. How can I remove the "-" (or any other character like a "/", "." or "( )") from the word once I've taken it into a string (an actual string, not char)? I know the answer is probably trivial but for some reason I can't remember... I think I need more sleep. Thanks for any help.

-aquaman

Last edited by AquamaN; 10-20-2005 at 05:58 PM.
 
Old 10-20-2005, 05:14 PM   #2
AquamaN
Member
 
Registered: Oct 2002
Location: Ohio, USA
Distribution: OS X 10.4.8, Ubuntu 6.10
Posts: 146

Original Poster
Rep: Reputation: 15
Or is there a way that when I take them into my

Code:
 list<input> inList;
that I can just have it ignore those characters so each word gets broken up automatically? Just a thought.
 
Old 10-20-2005, 06:17 PM   #3
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
I assume you're talking about C++, but without your second post there is no way of being able to tell. Just about every language has strings you know...

If thats the case it depends whether you're using std::string's or C-style char* strings. You didn't state that one either.

C style, I would scan once, find 'n' number of bad items, make a new array of (size - n), and copy the valid ones over.

Code:
int i, n, len;
char *orig, *copy;
orig = "a/string/with/a/.";

for(i = 0, n = 0, len = strlen(orig); i < len; i++)
  if(orig[i] == '/' || orig[i] == '.')  // check others if you want
    n++;

if(n > 0) {
  copy = new char[n];
  // and copy the orig string over, I have to run, sorry
} else {
  // string has no illegal chars'
}

Last edited by lowpro2k3; 10-20-2005 at 06:18 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP string replace question. apt Programming 1 04-26-2005 07:47 PM
String return question k1ll3r_x Programming 3 11-10-2004 02:46 PM
String Pointer Question (c/c++) greecesking Programming 2 08-26-2004 06:07 AM
script string question MadCactus Programming 4 08-14-2004 04:44 PM
simple C string question mvendramini Programming 9 09-30-2003 07:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration