home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 June / comonline0602.iso / software / cogitum / cociter.exe / CogitumH.___ / HTML / STRING.JS < prev    next >
Encoding:
JavaScript  |  2001-08-08  |  1.3 KB  |  61 lines

  1.  
  2. //
  3. // Removes spaces at the beginning and end of string
  4. //
  5. function fnStringRemoveOutterSpaces(szString)
  6. {
  7.     var szResult;
  8.     //
  9.     // remove leading spaces
  10.     var regexp = /^\s+/g;
  11.     szResult = szString.replace(regexp, "");
  12.     //
  13.     // remove ending spaces
  14.     regexp = /\s+$/g;
  15.     szResult = szResult.replace(regexp, "");
  16.     //
  17.     return szResult;
  18. };
  19.  
  20. //
  21. // Replaces all white spaces in the string with single space character
  22. //
  23. function fnStringDelimiterSingleSpace(szString)
  24. {
  25.     var szResult;
  26.     //
  27.     var regexp = /\s+/g;
  28.     szResult = szString.replace(regexp, " ");
  29.     //
  30.     return szResult;
  31. }
  32.  
  33. //
  34. // Prepare string for comparision
  35. // - removes leading and ending spaces
  36. // - replaces inner white space with single space char
  37. // - convert string to lower case
  38. //
  39. function fnStringPrepareForCompare(szString)
  40. {
  41.     var szResult = fnStringRemoveOutterSpaces(szString);
  42.     szResult = fnStringDelimiterSingleSpace(szResult)
  43.     szResult = szResult.toLowerCase();
  44.     //
  45.     return szResult;
  46. }
  47.  
  48. //
  49. // Compares 2 strings. Returns true if identical, otherwise false
  50. //
  51. function fnStringEqual(szString1, szString2)
  52. {
  53.     //
  54.     // prepare string for comparision
  55.     var szString1Ready = fnStringPrepareForCompare(szString1);
  56.     var szString2Ready = fnStringPrepareForCompare(szString2);
  57.     //
  58.     // compare
  59.     return (szString1Ready == szString2Ready);
  60. }
  61.