Sporkinator

Case insensitive string_replace()

Jun 20th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Case insensitive string_replace() script
  3.  
  4. Creator: Big J
  5.  
  6. Date: 02/09/2008
  7.  
  8. Description: Replaces one or all occurrences of a sub string within a string
  9.  
  10. Arg 0: String
  11. Arg 1: Sub String
  12. Arg 2: New String to replace Sub String with
  13. Arg 3: Whether to replace ALL occurrences
  14. */
  15. var str, substr, newstr, pos, str2, substr2, replace_all, len, temp;
  16. str = argument0;
  17. substr = argument1;
  18. newstr = argument2;
  19. replace_all = argument3;
  20. str2 = string_lower(str);
  21. substr2 = string_lower(substr);
  22.  
  23. while (true)
  24. {
  25.     len = string_length(substr);
  26.     pos = string_pos(substr2, str2);
  27.     if (pos)
  28.     {
  29.         temp = string_copy(str, pos, len);
  30.         str = string_replace(str, temp, newstr);
  31.         str2 = string_replace(str2, substr2, newstr);
  32.     }
  33.     else
  34.         break;
  35.     if (!replace_all)
  36.         break;
  37. }
  38. return str;
Advertisement
Add Comment
Please, Sign In to add comment