Wednesday, May 27, 2009

Lingo - "CString" like operation on strings

Coding in Lingo? (Macromedia and shockwave) here are some useful string utilities to help you





on new me
return me
end new

on trimLeadingWhiteSpace str
FuncName="trimLeadingWhiteSpace"
---------------------------------------------------------------
-- Name:trimLeadingWhiteSpace
-- Input:String
-- delete whitespace on the beginning of the string
--
--
-- Output:String
---------------------------------------------------------------

theCount = str.char.count
whiteSpace = " "
repeat with i = 1 to theCount
if whiteSpace contains str.char[i]then
next repeat
else
outStr = str.char[i..theCount]
exit repeat
end if
end repeat
return outStr
end




On TrimLeft me,str,subStr
FuncName="TrimLeft"
if(voidp(subStr)) then -- trim leading spaces
retStr= word 1 to the number of words in str of str
else
offsetNum=length(subStr)
retStr=chars (str, offsetNum+1, length(str))
end if
return retStr
end


on strReplace me,input, stringToFind, stringToInsert
FuncName="strReplace"
-- search and replace char in a string
output = ""
findLen = stringToFind.length - 1
repeat while input contains stringToFind
currOffset = offset(stringToFind, input)
output = output & input.char [1..currOffset]
delete the last char of output
output = output & stringToInsert
delete input.char [1.. (currOffset + findLen)]
end repeat
set output = output & input
return output
end



on GetFileTitle me,str,pref
offs=offset(pref,str)
repeat with i=offs down to 1
if(str.char[i..i]="\" or str.char[i..i]="/" ) then
posOfSlesh=i
i=1
end if
end repeat
substring=chars (str, 0, posOfSlesh)
ret=me.TrimLeft(str,substring)
ret=me.TrimRight(ret,pref)
return ret
end


on trimspaces me, t
FuncName="trimspaces"
return word 1 to the number of words in t of t
end



on SetLocalPath me, str
FuncName="SetLocalPath"
-- set the local path for local play
retStr=me.strReplace(str,"file://","")
if(retStr.char[1]="/") then
retStr=chars (retStr, 2,length(retStr))
retStr=me.strReplace(retStr,"/","\")
retstr=me.strReplace(retstr,"|",":")
else --local web path
retStr=me.strReplace(retStr,"/","\")
retstr=me.strReplace(retstr,"|",":")
retstr="\\"&retstr
end if
return retStr
end


on GetContent me, _url,str
FuncName="GetContent"
--Get the content of a known path (I.E. http://Test/league.htm -> http://Test/DswMedia)
EndOffset=offset(str,_url)
retStr=chars (_url, 0,EndOffset-1)
retstr=retstr&"DswMedia"
return retStr
end


on TrimRight me,_source,str
FuncName="TrimRight"
-- trim the right string from source
offsetNum=length(str)
retStr=chars (_source, 0, length(_source)-offsetNum)
retStr=me.trimspaces(retStr)
return retStr
end TrimRight



on String2List me,str
_list=[]
repeat with i=1 to str.length
if(str.char[i..i]<>",") then
_list.append(str.char[i..i])
end if
end repeat
return _list
end

0 תגובות:

Post a Comment

 
Home | About | Link | Link
Simple Proff Blogger Template Created By Herro | Inspiring By Busy Bee Woo Themes