CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Search text from a string?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
glenjoy



Joined: 18 Oct 2004
Posts: 21

View user's profile Send private message

Search text from a string?
PostPosted: Sun Jan 16, 2011 7:20 am     Reply with quote

If I have a string say, *string="jdslkajdsldjsladjABCDEFkjdfsljdsalk" and I want to check if ABCDEF do exists in that string, what is the best algorithm to use?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 7:40 am     Reply with quote

Try looking in the current CCS C Manual under Standard String Functions on page 266.
There you will find a function that searches for one string in another.

For example usage you can simply Google on that function and you will find a lot of examples
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 10:40 am     Reply with quote

There is also the question, of 'where is the string coming from'?.
If (for example), the long string is arriving from a source like the serial, then a state machine, may be a much more efficient 'algorithm'
What you do, is test each incoming character as it arrives, against the first character in the 'search' string (state 0). If this is seen, you advance to state one. State one, tests the arriving character against the next required value. If a good match, it moves to state two. If a failure, it moves back to state 0, and tries again. Similarly for each character in the incoming data.
Basically, there is normally only one test for each incoming character, and when the 'state' reaches the number of characters you are looking for, the required pattern has been seen.
'Walking' through a test pattern as data arrives, gives better efficiency in general, but at the cost of complexity. YPYMATYC.

Best Wishes
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 1:12 pm     Reply with quote

"YPYMATYC" ???? Google only finds something similar that is a pesticide. Hadn't heard that one before ... YMMV

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 1:57 pm     Reply with quote

You Pays Your Money And Takes Your Choice/Chance.

Best Wishes
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 2:14 pm     Reply with quote

:-) Thanks !!

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
djsb



Joined: 29 Jan 2011
Posts: 41

View user's profile Send private message

PostPosted: Sun Jan 30, 2011 7:59 am     Reply with quote

Hi,
I'm trying to extract \n , \f and \b from a serial character stream sent from a PC to a 16f628A using the USART module. I need to extract the escape sequence's as I'm trying to send clear screen, backspace and newline commands to an LCD using Flex_LCD.C. Can someone expand for me on the state machine algorithm. Any examples I can use to get me started.
I've got the characters echoing to the LCD without problems, just need to be able to send \n etc and have this recognised as a command.
Any help appreciated. Thanks.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Jan 30, 2011 9:18 am     Reply with quote

Ttelmah wrote:
You Pays Your Money And Takes Your Choice/Chance.


Should have them add it here:

http://www.cygwin.com/acronyms/
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group