NSString+MT.m 956 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // NSString+MT.m
  3. //
  4. // Created by Simon on 2019/3/22.
  5. // Copyright © 2019 Simon. All rights reserved.
  6. //
  7. #import "NSString+MT.h"
  8. @implementation NSString (MT)
  9. /**
  10. * URLEncode
  11. */
  12. - (NSString *)URLEncodedString
  13. {
  14. // CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
  15. // CharactersToLeaveUnescaped = @"[].";
  16. NSString * charaters = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";
  17. NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:charaters] invertedSet];
  18. return [self stringByAddingPercentEncodingWithAllowedCharacters:set];
  19. }
  20. /**
  21. * URLDecode
  22. */
  23. -(NSString *)URLDecodedString
  24. {
  25. return [self stringByRemovingPercentEncoding];
  26. }
  27. - (CGFloat)computeStringHeight{
  28. return [self boundingRectWithSize:CGSizeMake(ScreenWidth - kNumFrom375(30), 99999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kNumFrom375(14)]} context:nil].size.height+2;
  29. }
  30. @end