114 lines
3.4 KiB
Objective-C
114 lines
3.4 KiB
Objective-C
//
|
|
// NSString+Regex.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/9/14.
|
|
//
|
|
|
|
#import "NSString+Utils.h"
|
|
#import <CommonCrypto/CommonDigest.h>
|
|
|
|
@implementation NSString (Utils)
|
|
|
|
- (BOOL)isMobileDigital{
|
|
NSString *regex =@"^((1[3-9][0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
|
|
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
|
|
return [pred evaluateWithObject:self];
|
|
}
|
|
|
|
- (NSString *)MD5String {
|
|
const char *cstr = [self UTF8String];
|
|
unsigned char result[16];
|
|
CC_MD5(cstr, (CC_LONG)strlen(cstr), result);
|
|
return [NSString stringWithFormat:
|
|
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
|
result[0], result[1], result[2], result[3],
|
|
result[4], result[5], result[6], result[7],
|
|
result[8], result[9], result[10], result[11],
|
|
result[12], result[13], result[14], result[15]
|
|
];
|
|
}
|
|
|
|
+ (BOOL)versionContraprohibititinguishInthecaseofmerBWStt:(NSString *)first andNewStr: (NSString *)second{
|
|
if ([first compare:second options:NSNumericSearch] == NSOrderedAscending){
|
|
return NO;
|
|
}else if ([first compare:second options:NSNumericSearch] == NSOrderedSame){
|
|
return YES;
|
|
}else{
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
+ (NSString *)acquireDealFigurewithsttri:(NSString *)string{
|
|
if (string.floatValue <10000) {
|
|
return [NSString stringWithFormat:@"%@.0", string];
|
|
}
|
|
NSDecimalNumber *numberA = [NSDecimalNumber decimalNumberWithString:string];
|
|
NSDecimalNumber *numberB = [NSDecimalNumber decimalNumberWithString:@"10000"];
|
|
|
|
NSDecimalNumberHandler *roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundDown scale:2 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
|
|
|
|
NSDecimalNumber *numResult = [numberA decimalNumberByDividingBy:numberB withBehavior:roundingBehavior];
|
|
NSString *strResult = [numResult stringValue];
|
|
return [NSString stringWithFormat:YMLocalizedString(@"NS_String__Utils_0"), strResult];
|
|
}
|
|
|
|
+ (NSString *)sttriAboutIntrtowardsemporalStamp:(NSString *)timeStamp {
|
|
|
|
NSTimeInterval second = timeStamp.longLongValue / 1000;
|
|
NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
|
|
|
|
|
|
NSDateFormatter *engagementInitialiser = [[NSDateFormatter alloc] init];
|
|
[engagementInitialiser setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
|
|
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
|
|
[timeFormatter setDateFormat:@"HH:mm"];
|
|
|
|
NSDateFormatter *dayFormatter = [[NSDateFormatter alloc] init];
|
|
[dayFormatter setDateFormat:YMLocalizedString(@"NS_String__Utils_1")];
|
|
|
|
NSDateFormatter *yearFormatter = [[NSDateFormatter alloc] init];
|
|
[yearFormatter setDateFormat:YMLocalizedString(@"NS_String__Utils_2")];
|
|
|
|
|
|
NSTimeInterval timeInterval = [date timeIntervalSinceNow];
|
|
timeInterval = -timeInterval;
|
|
|
|
long temp = 0;
|
|
NSString *result;
|
|
|
|
BOOL isSameDay = [[NSCalendar currentCalendar] isDateInToday:date];
|
|
|
|
|
|
if (timeInterval < 60) {
|
|
return [NSString stringWithFormat:YMLocalizedString(@"NS_String__Utils_3")];
|
|
|
|
|
|
} else if((temp = timeInterval/60) < 60){
|
|
return [NSString stringWithFormat:YMLocalizedString(@"NS_String__Utils_4"),temp];
|
|
|
|
|
|
} else if((temp = temp/60) < 24 && isSameDay){
|
|
return [timeFormatter stringFromDate:date];
|
|
|
|
|
|
} else if((temp = temp/60) < 24 && !isSameDay){
|
|
return [dayFormatter stringFromDate:date];
|
|
|
|
|
|
} else if((temp = temp/30) < 30){
|
|
return [dayFormatter stringFromDate:date];
|
|
|
|
} else {
|
|
|
|
return [yearFormatter stringFromDate:date];
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
@end
|