Ignore punctuation when addressing word n of a string [more info]
Ken Ray
kray at sonsothunder.com
Mon Aug 11 20:51:00 EDT 2003
> Okay, so "word" automatically assumes white space as
> delimiter. I can't skim out the punctuation, so can someone
> suggest how I do the following. (This example is closer my
> real life problem).
Mark, here's a way to strip out punctuation - the regEx way:
on mouseUp
put "now, that is a string!" into tString
put GetWords(tString) into fld 1
end mouseUp
function GetWords pWhat
local tWordNoPuncs
put "" into tWordList
repeat for each word tWord in pWhat
get matchText(tWord,"([A-Za-z]*)",tWordNoPuncs)
put tWordNoPuncs&cr after tWordList
end repeat
delete last char of tWordList
return tWordList
end GetWords
> Within a bunch of text, I want to replace any string of pattern
>
> 00-000
>
> (where 0 is any integer and the dash is a literal dash) with
> a string of
>
> <A HREF="#00-000">00-000</A>
>
> In other words, I am looking to bracket the pattern string
> with an HTML index tag that uses the same literal string as a
> named target. Short of doing a char-by-char crawl, how can I
> accomplish this search and replace?
And for this one, try this:
on mouseUp
put "Yada 55-432 Yada" into tString
put HREFIt(tString) into fld 1
end mouseUp
function HREFIt pWhat
local tText
get matchText(pWhat,"([0-9][0-9][-][0-9][0-9][0-9])",tText)
put "<A HREF=" & quote & tText & quote & ">" & \
tText & "</A>" into tReplaceVal
replace tText with tReplaceVal in pWhat
return pWhat
end HREFIt
Have fun!
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list