stringTools.ts 911 B

123456789101112131415161718192021222324
  1. /**
  2. * Helper to manipulate strings
  3. */
  4. export class StringTools {
  5. /**
  6. * Checks for a matching suffix at the end of a string (for ES5 and lower)
  7. * @param str Source string
  8. * @param suffix Suffix to search for in the source string
  9. * @returns Boolean indicating whether the suffix was found (true) or not (false)
  10. */
  11. public static EndsWith(str: string, suffix: string): boolean {
  12. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  13. }
  14. /**
  15. * Checks for a matching suffix at the beginning of a string (for ES5 and lower)
  16. * @param str Source string
  17. * @param suffix Suffix to search for in the source string
  18. * @returns Boolean indicating whether the suffix was found (true) or not (false)
  19. */
  20. public static StartsWith(str: string, suffix: string): boolean {
  21. return str.indexOf(suffix) === 0;
  22. }
  23. }