Search content:

 

Personal Menu
Username:
Password:
Save password

Become a member

Forgot Password?

 

Don't miss these
Billenium Transitions Xtra v1.1
Director's Third Dimension : Fundamentals of 3D Programming in Director 8.5
vList Utility
Dir Player
cXtraCD
cXtraTransitions2
Rolling a Ball.
PDF Xtra
More encryption
CatCube
MediaMacros Xtras Mall
 

 

 

Behavior Text Services API

Added on 6/29/2001

 

Compatibilities:
D6_5 D7 D8 D8_5 Mac PC Script Shockwave

Rating:

Author: Magnamerc

These are a set of functions that provide basic text operations such as Find, Compare and Find & Replace. Also included here is an Insert Breaks function, and a Constrain String Size function.

-- Text Services API
-- (c) 2000 Michael Nieves

-- TSAPI_Find(search_string, content_string, case_sensitive, start)
-- returns index of match, or 0 if no match
-- case_sensitive is an optional boolean
-- start is optional char index, defaults to 1

-- TSAPI_Compare(string1, string2, case_sensitive)
-- returns 1 if string1 and string2 match, 0 if no match
-- case_sensitive is an optional boolean

-- TSAPI_Replace(search_string, replacement_string, content_string, case_sensitive, boundary)
-- returns string with replacement, or original string if no match
-- boundary can optionally be set to 'ALL' to replace all occurences of search_string
-- case_sensitive is an optional boolean

-- TSAPI_InsertBreaks(str, maxCharPerLine)
-- returns string with breaks inserted between words
-- maxCharPerLine specifies the maxlength of a line including spaces before a break is inserted

-- TSAPI_ConstrainStringSize(str, maxLength)
-- returns string truncated to max length, appends elipses

on TSAPI_Find search_string, content_string, case_sensitive, start
  if start = EMPTY OR start = VOID then
    set start to 1
  end if
  
  repeat with i = start to length(content_string)
    if case_sensitive = TRUE then
      if charToNum(char 1 of search_string) = charToNum(char i of content_string) then
        set count to i
        
        repeat with k = 1 to length(search_string)
          if charToNum(char k of search_string) = charToNum(char count of content_string) then
            set count to count + 1
          else
            exit repeat
          end if
        end repeat
      end if
    else
      if char 1 of search_string = char i of content_string then
        set count to i
        
        repeat with k = 1 to length(search_string)
          if char k of search_string = char count of content_string then
            set count to count + 1
          else
            exit repeat
          end if
        end repeat        
      end if      
    end if
    
    if k > length(search_string) then
      return i
    end if
  end repeat
  
  return 0
end TSAPI_Find


on TSAPI_Compare string1, string2, case_sensitive
  if length(string1) <> length(string2) then
    return 0
  end if
  
  if case_sensitive = TRUE then
    repeat with k = 1 to length(string1)
      if charToNum(char k of string1) <> charToNum(char k of string2) then
        return 0
      end if
    end repeat
    
    return 1
  else    
    repeat with k = 1 to length(string1)
      if char k of string1 <> char k of string2 then
        return 0
      end if
    end repeat
    
    return 1
  end if
  
  return 0
end TSAPI_Compare


on TSAPI_Replace search_string, replacement_string, content_string, case_sensitive, boundary
  set index to TSAPI_Find(search_string, content_string, case_sensitive)
  
  if index = 0 then
    return content_string
  end if
  
  repeat with i = 1 to length(content_string)
    if i = index then
      set new_string to new_string & replacement_string
      
      set start to i + (length(search_string))
      
      if boundary = "ALL" then
        set index to TSAPI_Find(search_string, content_string, case_sensitive, start)
      end if
      
    else if i >= start then
      set new_string to new_string & char i of content_string
    end if      
  end repeat  
  
  return new_string  
end TSAPI_Replace


on TSAPI_InsertBreaks(str, maxCharPerLine)
  set the itemDelimiter to SPACE
  new_str = EMPTY
  
  repeat with i = 1 to (the number of items in str)
    if new_str <> EMPTY then
      temp_str = new_str & SPACE & (item i of str)
      
      if length(temp_str) > maxCharPerLine then
        temp_str = new_str & RETURN & (item i of str)
        maxCharPerLine = maxCharPerLine * 2
      end if
      
      new_str = temp_str
    else
      new_str = (item i of str)
    end if
  end repeat
  
  return new_str
end


on TSAPI_ConstrainStringSize(str, maxLength)
  if length(str) > maxLength then
    str = chars(str, 1, (maxLength - 6)) & "...   "
  else
    repeat with k = length(str) to maxLength - 1
      str = str & SPACE
    end repeat
  end if
  
  return str
end

 


Upload Provided by ABCUpload ASP

Contact

MMI
22 West Court Sq
Suite 2C
Newnan, GA 30263
USA

Fax - (206) 339-5833

Send e-mail