Re: I need help! Substrings
turbosol <[email protected]> Wed, 30 May 2007 11:59:17 -0700 (PDT)
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
this is what I have been able to write so far...
val index = 0;
fun inc x= x+1;
fun findmatch(S,L) =
if null S then ~1
else if null L then ~1
else if hd(S) = hd(L) then checkrest(tl S,tl L)
else findmatch(S, tl L) + inc(index);
fun checkrest(S, L) =
if null(tl S) then index
else if hd(tl S)= hd(tl L) then checkrest(tl S, tl L)
else findmatch(S, tl L);
fun substring (S,L)= findmatch(explode S,explode L);
substring("abc","bdabcd");
////// however, this does not run, it throws errors about the explode.
Also, I know that if this was able to compile, it will return the size of
the list if the string is not found. It is also only checking for the first
char in the string S, and does nothing with the rest as of now.
turbosol wrote:
>
> So i signed up for my last compscience class so i can graduate... the
> class i needed was canceled so i was put into a more difficult class for
> majors. Comp science is my minor... anyways, I am currently doing twice
> the work i would normally do in half the time. I am lost. if anyone can
> help me, i would appreciate it SOOO much.
>
> I need to write a function SubString : string * string -> int that checks
> whether the first string is a substring of the second (case sensitive).
> return the index position (starting from 0) if the string is a substring
> or -1 otherwise. for multiple occurances, just return the index of the
> first appearance. you may assume both input parameters are strings.
>
> subString("ab","abcdefg")=> 1
> subString("aaa","aaaa")=>0
> subString("bc","absge") =>-1
> subString("ab","cdabd") => 2
>
--
View this message in context: http://www.nabble.com/I-need-help%21--Substrings-tf3836438.html#a10880352
Sent from the SML/NJ mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/