NSString+TUIUtil.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // NSString+TUICommon.h
  3. //
  4. // Created by Alexi on 12-11-5.
  5. // Copyright (c) 2012 . All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import <UIKit/UIKit.h>
  9. char tui_pinyinFirstLetter(unsigned short hanzi);
  10. @interface NSString (TUIUtil)
  11. /**
  12. * Hash the string using md5
  13. */
  14. + (NSString *)md5String:(NSString *)str;
  15. - (NSString *)md5;
  16. /**
  17. * Get the first letter of Pinyin
  18. */
  19. - (NSString *)firstPinYin;
  20. - (NSString *)safePathString;
  21. + (BOOL)isEmpty:(NSString *)string;
  22. /**
  23. * compare two version
  24. *
  25. * @param sourVersion *.*.*.*
  26. * @param desVersion *.*.*.*
  27. * @returns No,sourVersion is less than desVersion; YES, the statue is opposed
  28. */
  29. + (BOOL)compareVerison:(NSString *)sourVersion withDes:(NSString *)desVersion;
  30. /**
  31. * Whether the current string contains only whitespace and newlines
  32. */
  33. - (BOOL)isWhitespaceAndNewlines;
  34. /**
  35. * Remove whitespace before and after a string, excluding newlines
  36. */
  37. - (NSString *)trim;
  38. /**
  39. * Remove all whitespace from a string
  40. */
  41. - (NSString *)removeWhiteSpace;
  42. - (NSString *)removeNewLine;
  43. /**
  44. * The string with URL-Encoding
  45. */
  46. - (NSString *)stringByUrlEncoding;
  47. /**
  48. * Convert the first letter of a string to uppercase
  49. */
  50. - (NSString *)capitalize;
  51. /**
  52. * Determines whether a string starts with the given string, ignoring case
  53. */
  54. - (BOOL)startsWith:(NSString *)str;
  55. - (BOOL)startsWith:(NSString *)str Options:(NSStringCompareOptions)compareOptions;
  56. /**
  57. * Determines whether a string ends with the given string, ignoring case
  58. */
  59. - (BOOL)endsWith:(NSString *)str;
  60. - (BOOL)endsWith:(NSString *)str Options:(NSStringCompareOptions)compareOptions;
  61. /**
  62. * Determines whether a string contains the given string, ignoring case
  63. */
  64. - (BOOL)tui_containsString:(NSString *)str;
  65. - (BOOL)tui_containsString:(NSString *)str Options:(NSStringCompareOptions)compareOptions;
  66. /**
  67. * Determines whether a string equals with the given string, ignoring case
  68. */
  69. - (BOOL)equalsString:(NSString *)str;
  70. - (NSString *)emjoiText;
  71. #pragma mark Hashing
  72. #if kSupportGTM64
  73. - (NSString *)base64Encoding;
  74. #endif
  75. - (NSString *)valueOfLabel:(NSString *)label;
  76. - (NSString *)substringAtRange:(NSRange)rang;
  77. - (NSUInteger)utf8Length;
  78. - (BOOL)isContainsEmoji;
  79. - (NSString *)cutBeyondTextInLength:(NSInteger)maxLenth;
  80. - (CGSize)textSizeIn:(CGSize)size font:(UIFont *)font;
  81. - (CGSize)textSizeIn:(CGSize)size font:(UIFont *)font breakMode:(NSLineBreakMode)breakMode;
  82. - (CGSize)textSizeIn:(CGSize)size font:(UIFont *)font breakMode:(NSLineBreakMode)breakMode align:(NSTextAlignment)alignment;
  83. - (CGFloat)widthFromFont:(UIFont *)font;
  84. @end