C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 29th, 2006, 11:39 PM
somewe somewe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 2 somewe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 48 sec
Reputation Power: 0
All About Strings.

I'm having problem because I don't know how could I code my program.

Example:

Sentence: "You and I are perfect!"

How can I manage to get the line "I" to "perfect!"?

Using:

Start String = I
End String = ct!

That would result to:

I are perfect!

The concept is that I would specify the start of string and the end of the string like a keyword but the result would be the whole line from I to perfect?

Reply With Quote
  #2  
Old June 30th, 2006, 03:35 AM
ossinator ossinator is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 40 ossinator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 11 m 12 sec
Reputation Power: 4
Send a message via ICQ to ossinator
If you're using c++ strings, it is really easy.
You just need the find() function. Some simple code:

Code:
#include <iostream>
#include <string>
using namespace std;
string fstringfinder(string start, string end, string search)
{
string return_value;

int start_loc = (int) search.find(start,0); //find the location of the starting string
int end_loc = (int) search.find(end,0); //find location of ending string
int len_substr = end_loc - start_loc  + 1; //the length of the new string
if ((end_loc < start_loc) || (start_loc < 0) || (end_loc < 0)) 
//error - either the starting string is after the ending one, or one 
//of the 2 strings is not found in the searched string
return "Error!"; //good idea to be substituted with something more practical, like a list of error codes.
else
return_value= search.substr(start_loc,len_substr);
return return_value;
}


int main()
{
string a("0123456789");
cout << fstringfinder("4","7",a);
return 0;


If you are using bare c it's a little more complicated, post again and i'll try to explain to you
Hope that helps

Reply With Quote
  #3  
Old July 2nd, 2006, 10:50 AM
somewe somewe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 2 somewe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 48 sec
Reputation Power: 0
no not pure C i go for C++ but too bad i cannot understand much though.. but thanks for your post

If you could contruct me a prog that opens text files in the current dir and searches the given start and endstrings and then compiling them into one txt file


somewhat string isolation...


BTW thanks again

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > All About Strings.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT