Aucune description

FLStringHelper.m 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. //
  2. // FLStringHelper.m
  3. // FirstLink
  4. //
  5. // Created by unicode on 14-9-25.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access
  9. #import "NSDate+Category.h"
  10. @implementation NSString (MyAdditions)
  11. - (NSString *)md5
  12. {
  13. const char *cStr = [self UTF8String];
  14. unsigned char result[32];
  15. CC_MD5( cStr, (CC_LONG)strlen(cStr), result );
  16. return [NSString stringWithFormat:
  17. @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  18. result[0],result[1],result[2],result[3],
  19. result[4],result[5],result[6],result[7],
  20. result[8],result[9],result[10],result[11],
  21. result[12],result[13],result[14],result[15],
  22. result[16], result[17],result[18], result[19],
  23. result[20], result[21],result[22], result[23],
  24. result[24], result[25],result[26], result[27],
  25. result[28], result[29],result[30], result[31]];
  26. }
  27. @end
  28. #import "FLStringHelper.h"
  29. @implementation FLStringHelper
  30. + (NSString*)convertNumberToString:(int)num {
  31. return [NSString stringWithFormat:@"%d", num];
  32. }
  33. + (CGRect)rectOfString:(NSString*)text font:(UIFont*)font width:(CGFloat)width {
  34. NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
  35. font, NSFontAttributeName,
  36. nil];
  37. if (!text || text.length == 0) {
  38. return CGRectZero;
  39. }
  40. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text
  41. attributes:attributesDictionary];
  42. CGRect rect = [string boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX)
  43. options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
  44. context:nil];
  45. return rect;
  46. }
  47. + (CGRect)rectOfString:(NSString *)text font:(UIFont *)font height:(CGFloat)height {
  48. if (![FLStringHelper isValidString:text]) return CGRectZero;
  49. NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
  50. font, NSFontAttributeName,
  51. nil];
  52. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text
  53. attributes:attributesDictionary];
  54. CGRect rect = [string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height)
  55. options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
  56. context:nil];
  57. return rect;
  58. }
  59. + (CGSize)sizeOfAttributeString:(NSString *)text font:(UIFont *)font width:(CGFloat)width maxRow:(int)maxRow {
  60. if (![FLStringHelper isValidString:text]) return CGSizeZero;
  61. NSAttributedString *attributeString = [[NSAttributedString alloc] initWithString:text
  62. attributes:@{NSFontAttributeName : font}];
  63. return [TTTAttributedLabel sizeThatFitsAttributedString:attributeString
  64. withConstraints:CGSizeMake(width, CGFLOAT_MAX)
  65. limitedToNumberOfLines:maxRow];
  66. }
  67. + (NSString*)replaceNilWithEmpty:(NSString *)string
  68. {
  69. if (!string) {
  70. return @"";
  71. }
  72. return string;
  73. }
  74. + (NSString*)convertFenToYuan:(NSString *)fen {
  75. if (!fen || fen.length == 0) {
  76. return @"";
  77. }
  78. // TODO: 格式检查校验
  79. NSNumber *yuan = [NSNumber numberWithDouble:fen.doubleValue/100];
  80. return [NSString stringWithFormat:@"%.2lf",yuan.doubleValue];
  81. }
  82. + (CGFloat)convertFenStringToYuanValue:(NSString *)fenStr{
  83. if (!fenStr || ![fenStr isKindOfClass:[NSString class]] || fenStr.length == 0) {
  84. return 0.0f;
  85. }
  86. return fenStr.floatValue / 100.0f;
  87. }
  88. + (NSString *)convertFenToRMBmoneyString:(NSString*)fen{
  89. return [NSString stringWithFormat:@"¥%@", [self convertFenToYuan:fen]];
  90. }
  91. #pragma mark - Time Formate
  92. + (NSString*)componentOfDay:(NSString*)time {
  93. if (time == nil || time.length <= 0) {
  94. return nil;
  95. }
  96. return [time substringToIndex:10];
  97. }
  98. + (NSDateFormatter *)dateFormat {
  99. static NSDateFormatter *dateFormat = nil;
  100. static dispatch_once_t once_token;
  101. dispatch_once(&once_token, ^{
  102. dateFormat = [[NSDateFormatter alloc] init];
  103. });
  104. return dateFormat;
  105. }
  106. + (NSString*)convertStringToTipTime:(NSString *)time {
  107. return [self convertStringToTipTime:time formate:@"yyyy-MM-dd HH:mm:ss"];
  108. }
  109. + (NSString *)convertStringToTipTime:(NSString *)time formate:(NSString *)formate{
  110. if (!time) {
  111. return @"1分钟前";
  112. }
  113. // 2014-10-12T12:12:12
  114. NSDateFormatter *dateFormat = [FLStringHelper dateFormat];
  115. [dateFormat setDateFormat:formate];
  116. NSMutableString *mutString = [NSMutableString stringWithString:time];
  117. NSString *temp = [mutString stringByReplacingOccurrencesOfString:@"T"
  118. withString:@" "];
  119. NSDate *date = [dateFormat dateFromString:temp];
  120. // TODO: relpace current with time from server
  121. NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitMinute | NSCalendarUnitHour | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear
  122. fromDate:date
  123. toDate:[NSDate date]
  124. options:0];
  125. if (components.year > 0 || components.month > 0 || components.day > 0) {
  126. return [FLStringHelper componentOfDay:time];
  127. }
  128. if (components.hour > 0) {
  129. return [NSString stringWithFormat:@"%ld小时前", (long)components.hour];
  130. }
  131. if (components.minute > 0) {
  132. return [NSString stringWithFormat:@"%ld分钟前", (long)components.minute];
  133. }
  134. return @"1 分钟前";
  135. }
  136. + (NSDateComponents*)convertSecondToComponents:(NSTimeInterval)second {
  137. NSDate *startDate = [NSDate date];
  138. NSDate *endDate = [NSDate dateWithTimeInterval:second sinceDate:startDate];
  139. NSCalendarUnit unit = NSCalendarUnitSecond | NSCalendarUnitMinute | NSCalendarUnitHour | NSCalendarUnitDay;
  140. NSDateComponents *components = [[NSCalendar currentCalendar] components:unit
  141. fromDate:startDate
  142. toDate:endDate
  143. options:NSCalendarWrapComponents];
  144. return components;
  145. }
  146. + (NSString*)dateForMessage:(NSDate *)date {
  147. if (!date) return nil;
  148. NSDateFormatter *dateFormat = [FLStringHelper dateFormat];
  149. [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  150. return [dateFormat stringFromDate:date];
  151. }
  152. + (NSString*)convertDate:(NSDate *)date formate:(NSString *)formate {
  153. if (!date) return nil;
  154. NSDateFormatter *dateFormat = [FLStringHelper dateFormat];
  155. [dateFormat setDateFormat:formate];
  156. return [dateFormat stringFromDate:date];
  157. }
  158. + (NSDate *)convertToDateFromString:(NSString *)string {
  159. if (!string || string.length == 0) return nil;
  160. NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
  161. formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
  162. NSString *dateString = [string stringByReplacingOccurrencesOfString:@"T" withString:@" "];
  163. return [formatter dateFromString:dateString];
  164. }
  165. + (NSDate *)convertToShortDateFromString:(NSString *)string{
  166. if (!string || string.length == 0) return nil;
  167. NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
  168. formatter.dateFormat = @"yyyy-MM-dd";
  169. NSString *dateString = [string stringByReplacingOccurrencesOfString:@"T" withString:@" "];
  170. return [formatter dateFromString:dateString];
  171. }
  172. + (NSString *)convertDictionary2String:(NSDictionary *)dict {
  173. if (!dict) return nil;
  174. NSError *error;
  175. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
  176. options:NSJSONWritingPrettyPrinted
  177. error:&error];
  178. if (!error) {
  179. return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  180. }
  181. return nil;
  182. }
  183. + (NSString*)nicknames:(NSArray*)array count:(int)count {
  184. NSMutableString *mutableString = [NSMutableString string];
  185. for (int index = 0; index < array.count && index < count; index++) {
  186. [mutableString appendString:array[index]];
  187. [mutableString appendString:@","];
  188. }
  189. if (mutableString.length > 0) {
  190. return [mutableString substringToIndex:mutableString.length-1];
  191. }
  192. return nil;
  193. }
  194. #pragma mark - CDN Paramater String
  195. + (NSString*)cdnParamaterString:(int)width {
  196. return [NSString stringWithFormat:@"@%dw_90Q_1l_%dx", width, (int)[UIScreen mainScreen].scale];
  197. }
  198. + (NSString*)cdnParamaterString:(int)width height:(int)height {
  199. return [NSString stringWithFormat:@"@%dw_%dh_1e_1l_1c_%dx_1o", width, height, (int)[UIScreen mainScreen].scale];
  200. }
  201. + (NSString *)convertToShortDateStringFromString:(NSString *)timeString {
  202. if (!timeString || timeString.length == 0) return nil;
  203. NSRange range = [timeString rangeOfString:@"T"];
  204. NSString *shortString = [timeString substringToIndex:range.location];
  205. return shortString;
  206. }
  207. + (NSString *)convertToPredigestStringFromString:(NSString *)timeString {
  208. return [self convertToPredigestStringFromString:timeString baseTime:nil];
  209. }
  210. + (NSString *)convertToPredigestStringFromString:(NSString *)timeString baseTime:(NSDate *)baseTime{
  211. if (!timeString || timeString.length == 0) return nil;
  212. NSDate *nowDate = [NSDate date];
  213. if ([baseTime isKindOfClass:[NSDate class]]) {
  214. nowDate = baseTime;
  215. }
  216. NSString *shortDateString = [FLStringHelper convertToShortDateStringFromString:timeString];
  217. NSDate *compareTime = [FLStringHelper convertToDateFromString:timeString];
  218. NSTimeInterval countTimeSecond = [nowDate timeIntervalSinceDate:compareTime];
  219. if (countTimeSecond <= 0) return nil;
  220. NSDateComponents *dateComponent = [FLStringHelper convertSecondToComponents:countTimeSecond];
  221. if (dateComponent.day > 0) return shortDateString;
  222. if (dateComponent.hour > 0) return [NSString stringWithFormat:@"%ld小时前", (long)dateComponent.hour];
  223. if (dateComponent.minute > 0) return [NSString stringWithFormat:@"%ld分钟前", (long)dateComponent.minute];
  224. return [NSString stringWithFormat:@"1分钟前"];
  225. }
  226. + (NSString *)convertToPredigestStringFromTimeInterval:(NSTimeInterval)timeInterval shortTimeStr:(NSString *)shortTimeStr{
  227. if (timeInterval <= 0) return nil;
  228. NSDateComponents *dateComponent = [FLStringHelper convertSecondToComponents:timeInterval];
  229. if (dateComponent.day > 0) return shortTimeStr;
  230. if (dateComponent.hour > 0) return [NSString stringWithFormat:@"%ld小时前", (long)dateComponent.hour];
  231. if (dateComponent.minute > 0) return [NSString stringWithFormat:@"%ld分钟前", (long)dateComponent.minute];
  232. return [NSString stringWithFormat:@"1分钟前"];
  233. }
  234. + (NSString *)convertTimeIntervalToCountString:(NSTimeInterval)timeInterval {
  235. if (timeInterval <= 0) return @"0天0小时0分0秒";
  236. NSDateComponents *dateComponet = [FLStringHelper convertSecondToComponents:timeInterval];
  237. NSString *days = [NSString stringWithFormat:@"%ld", (long)dateComponet.day];
  238. NSString *hours = [NSString stringWithFormat:@"%ld", (long)dateComponet.hour];
  239. NSString *minuts = [NSString stringWithFormat:@"%ld", (long)dateComponet.minute];
  240. NSString *seconds = [NSString stringWithFormat:@"%ld", (long)dateComponet.second];
  241. NSString *normalString = [NSString stringWithFormat:@"%@天%@小时%@分%@秒", days, hours, minuts, seconds];
  242. return normalString;
  243. }
  244. + (NSString *)convertTimeIntervalToHourCountString:(NSTimeInterval)timeInterval {
  245. if (timeInterval <= 0) return @"0小时0分0秒";
  246. NSDateComponents *dateComponet = [FLStringHelper convertSecondToComponents:timeInterval];
  247. NSString *hours = [NSString stringWithFormat:@"%ld", ((long)dateComponet.hour + dateComponet.day*24)];
  248. NSString *minuts = [NSString stringWithFormat:@"%02ld", (long)dateComponet.minute];
  249. NSString *seconds = [NSString stringWithFormat:@"%02ld", (long)dateComponet.second];
  250. NSString *normalString = [NSString stringWithFormat:@"%@小时%@分%@秒", hours, minuts, seconds];
  251. return normalString;
  252. }
  253. + (NSString *)convertTimeIntervalToHourCountStringStyleColon:(NSTimeInterval)timeInterval {
  254. if (timeInterval <= 0) return @"00:00:00";
  255. NSDateComponents *dateComponet = [FLStringHelper convertSecondToComponents:timeInterval];
  256. NSString *hours = [NSString stringWithFormat:@"%ld", ((long)dateComponet.hour + dateComponet.day*24)];
  257. NSString *minuts = [NSString stringWithFormat:@"%02ld", (long)dateComponet.minute];
  258. NSString *seconds = [NSString stringWithFormat:@"%02ld", (long)dateComponet.second];
  259. NSString *normalString = [NSString stringWithFormat:@"%@:%@:%@", hours, minuts, seconds];
  260. return normalString;
  261. }
  262. + (NSString *)convertToCommonFormateFromString:(NSString *)timeString baseTime:(NSString *)baseTime{
  263. if (!timeString || timeString.length == 0) return nil;
  264. NSDate *nowDate = [NSDate date];
  265. if ([FLStringHelper isValidString:baseTime]) {
  266. nowDate = [FLStringHelper convertToDateFromString:baseTime];
  267. }
  268. NSDate *compareTime = [FLStringHelper convertToDateFromString:timeString];
  269. NSTimeInterval countTimeSecond = [nowDate timeIntervalSinceDate:compareTime];
  270. if (countTimeSecond <= 0) return nil;
  271. NSDateComponents *dateComponent = [self convertSecondToComponents:countTimeSecond baseTime:baseTime];
  272. if (dateComponent.day > 0) return [self convertToTimeStrNoYear:timeString];
  273. if (dateComponent.hour > 0) return [NSString stringWithFormat:@"%ld小时前", (long)dateComponent.hour];
  274. if (dateComponent.minute > 3) return [NSString stringWithFormat:@"%ld分钟前", (long)dateComponent.minute];
  275. return [NSString stringWithFormat:@"刚刚"];
  276. }
  277. +(NSDateComponents *)convertToComponentsFormateFromString:(NSString *)timeString baseTime:(NSString *)baseTime{
  278. if (!timeString || timeString.length == 0) return nil;
  279. NSDate *nowDate = [NSDate date];
  280. if ([FLStringHelper isValidString:baseTime]) {
  281. nowDate = [FLStringHelper convertToDateFromString:baseTime];
  282. }
  283. NSDate *compareTime = [FLStringHelper convertToDateFromString:timeString];
  284. NSTimeInterval countTimeSecond = [compareTime timeIntervalSinceDate:nowDate];
  285. if (countTimeSecond <= 0) return nil;
  286. NSDateComponents *dateComponent = [self convertSecondToComponents:countTimeSecond baseTime:baseTime];
  287. return dateComponent;
  288. }
  289. + (NSString *)convertToTimeStrNoYear:(NSString *)timeStr{
  290. NSDateFormatter *dateFormat = [FLStringHelper dateFormat];
  291. [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  292. NSMutableString *mutString = [NSMutableString stringWithString:timeStr];
  293. NSString *temp = [mutString stringByReplacingOccurrencesOfString:@"T"
  294. withString:@" "];
  295. NSDate *date = [dateFormat dateFromString:temp];
  296. if (!date) return nil;
  297. NSString *fullString = [dateFormat stringFromDate:date];
  298. if (fullString.length >= 19){
  299. NSString *dayStr = [fullString substringWithRange:NSMakeRange(5, 5)];
  300. NSString *hourStr = [fullString substringWithRange:NSMakeRange(11, 5)];
  301. fullString = [dayStr stringByAppendingString:@" "];
  302. fullString = [fullString stringByAppendingString:hourStr];
  303. }
  304. return fullString;
  305. }
  306. + (NSDateComponents*)convertSecondToComponents:(NSTimeInterval)second baseTime:(NSString *)baseTime{
  307. NSDate *startDate = [FLStringHelper convertToDateFromString:baseTime];
  308. NSDate *endDate = [NSDate dateWithTimeInterval:second sinceDate:startDate];
  309. NSCalendarUnit unit = NSCalendarUnitSecond | NSCalendarUnitMinute | NSCalendarUnitHour | kCFCalendarUnitDay;
  310. NSDateComponents *components = [[NSCalendar currentCalendar] components:unit
  311. fromDate:startDate
  312. toDate:endDate
  313. options:NSCalendarWrapComponents];
  314. return components;
  315. }
  316. + (NSTimeInterval)timeIntervalFromString:(NSString *)dateString {
  317. NSDate *date = [FLStringHelper convertToDateFromString:dateString];
  318. return [date timeIntervalSince1970];
  319. }
  320. + (BOOL)isUrlString:(NSString *)string {
  321. if (string.length < 5) return NO;
  322. NSString *headerString = [string substringToIndex:4];
  323. if ([headerString isEqualToString:@"http"]) return YES;
  324. return NO;
  325. }
  326. + (NSAttributedString *)attStringWithText:(NSString *)text color:(UIColor *)color font:(UIFont *)font lineSpace:(CGFloat)lineSpace{
  327. if (text.length == 0) return nil;
  328. NSMutableAttributedString *attM = [[NSMutableAttributedString alloc]initWithString:text];
  329. NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
  330. [paraStyle setLineSpacing:lineSpace];
  331. [attM addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)];
  332. if (color) {
  333. [attM addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, text.length)];
  334. }
  335. if (font) {
  336. [attM addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, text.length)];
  337. }
  338. return attM;
  339. }
  340. + (NSAttributedString *)attStringWithText:(NSString *)text lineSpace:(CGFloat)lineSpace {
  341. return [self attStringWithText:text color:nil font:nil lineSpace:lineSpace];
  342. }
  343. + (CGSize)sizeOfAttributeString:(NSString*)text lineSpace:(CGFloat)lineSpace width:(CGFloat)width font:(UIFont *)font maxRow:(NSInteger)maxRow{
  344. if (![FLStringHelper isValidString:text]) return CGSizeZero;
  345. NSMutableAttributedString *attM = [[NSMutableAttributedString alloc]initWithString:text];
  346. NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
  347. [paraStyle setLineSpacing:lineSpace];
  348. [attM addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)];
  349. [attM addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, text.length)];
  350. return [attM boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
  351. }
  352. + (NSAttributedString *)attStringWithText:(NSString *)text color:(UIColor *)color font:(UIFont *)font subText:(NSString *)subText subColor:(UIColor *)subColor subFont:(UIFont *)subFont {
  353. NSMutableAttributedString *mutAttributedString = [[NSMutableAttributedString alloc] init];
  354. if (text.length > 0 && color && font) {
  355. NSDictionary * attribtues = @{NSFontAttributeName:font,
  356. NSForegroundColorAttributeName:color};
  357. NSAttributedString * attribtueString = [[NSAttributedString alloc] initWithString:text attributes:attribtues];
  358. [mutAttributedString appendAttributedString:attribtueString];
  359. }
  360. if (subText.length > 0 && subColor && subFont) {
  361. NSDictionary * attribtues = @{NSFontAttributeName:subFont,
  362. NSForegroundColorAttributeName:subColor,
  363. NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),
  364. NSStrikethroughColorAttributeName:subColor};
  365. NSAttributedString * attribtueString = [[NSAttributedString alloc] initWithString:subText attributes:attribtues];
  366. [mutAttributedString appendAttributedString:attribtueString];
  367. }
  368. return mutAttributedString;
  369. }
  370. + (id)convertStringToJson:(NSString *)string {
  371. if (!string) {
  372. return nil;
  373. }
  374. NSError *error;
  375. NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
  376. NSDictionary *json = [NSJSONSerialization JSONObjectWithData: data
  377. options: NSJSONReadingMutableContainers
  378. error: &error];
  379. if (!error) {
  380. return json;
  381. }
  382. return nil;
  383. }
  384. + (BOOL)isValidString:(NSString *)string{
  385. if ([string isKindOfClass:[NSString class]] && string.length) {
  386. return YES;
  387. }
  388. return NO;
  389. }
  390. + (NSString *)jsonStrWithDict:(NSDictionary *)dict{
  391. if (!dict) return nil;
  392. NSError *error;
  393. NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  394. #ifdef DEBUG
  395. if (error){
  396. NSLog(@"json serialization fail error = %@", error.localizedDescription);
  397. }
  398. #endif
  399. if (data){
  400. NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
  401. return string;
  402. }
  403. return nil;
  404. }
  405. + (NSString *)convertToShortNumStr:(NSInteger)count{
  406. if (count < 0) return nil;
  407. if (count < 10000){
  408. return [NSString stringWithFormat:@"%ld", count];
  409. }else{
  410. NSInteger num = floor(count / 10000.0f);
  411. return [NSString stringWithFormat:@"%ld万", num];
  412. }
  413. }
  414. @end