NSString+HXExtension.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // NSString+HXExtension.m
  3. // HXPhotoPickerExample
  4. //
  5. // Created by Silence on 2019/1/10.
  6. // Copyright © 2019年 Silence. All rights reserved.
  7. //
  8. #import "NSString+HXExtension.h"
  9. @implementation NSString (HXExtension)
  10. - (NSString *)hx_countStrBecomeComma {
  11. if (self.length < 3) {
  12. return self;
  13. }
  14. int count = 0;
  15. long long int a = self.longLongValue;
  16. while (a != 0) {
  17. count++;
  18. a /= 10;
  19. }
  20. NSMutableString *string = [NSMutableString stringWithString:self];
  21. NSMutableString *newstring = [NSMutableString string];
  22. while (count > 3) {
  23. count -= 3;
  24. NSRange rang = NSMakeRange(string.length - 3, 3);
  25. NSString *str = [string substringWithRange:rang];
  26. [newstring insertString:str atIndex:0];
  27. [newstring insertString:@"," atIndex:0];
  28. [string deleteCharactersInRange:rang];
  29. }
  30. [newstring insertString:string atIndex:0];
  31. return newstring;
  32. }
  33. + (NSString *)hx_fileName {
  34. CFUUIDRef uuid = CFUUIDCreate(nil);
  35. NSString *uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuid);
  36. CFRelease(uuid);
  37. NSString *uuidStr = [[uuidString stringByReplacingOccurrencesOfString:@"-" withString:@""] lowercaseString];
  38. NSString *name = [NSString stringWithFormat:@"%@",uuidStr];
  39. NSString *fileName = @"";
  40. NSDate *nowDate = [NSDate date];
  41. NSString *dateStr = [NSString stringWithFormat:@"%ld", (long)[nowDate timeIntervalSince1970]];
  42. NSString *numStr = [NSString stringWithFormat:@"%d",arc4random()%10000];
  43. fileName = [fileName stringByAppendingString:@"hx"];
  44. fileName = [fileName stringByAppendingString:dateStr];
  45. fileName = [fileName stringByAppendingString:numStr];
  46. return [NSString stringWithFormat:@"%@%@",name,fileName];
  47. }
  48. @end