// // NSString+YLString.h // YoungCatogory // // Created by kuxuan on 2017/7/12. // Copyright © 2017年 kuxuan. All rights reserved. // #import #import @interface NSString (YLString) /** Creates a new string that contains a generated UUID. @return The path to the app's Caches folder. */ + (NSString *_Nonnull)stringWithUUID; /** creates an MD5 @return returns an MD5 hash for the receiver. */ - (NSString *_Nonnull)md5; /** Determines the path to the Library/Caches folder in the current application's sandbox. The return value is cached on the first call. @return The path to the app's Caches folder. */ + (NSString *_Nullable)cachesPath; /** Determines the path to the Documents folder in the current application's sandbox. The return value is cached on the first call. @return The path to the app's Documents folder. */ + (NSString *_Nonnull)documentsPath; /**------------------------------------------------------------------------------------- @name Getting Temporary Paths --------------------------------------------------------------------------------------- */ /** Determines the path for temporary files in the current application's sandbox. The return value is cached on the first call. This value is different in Simulator than on the actual device. In Simulator you get a reference to /tmp wheras on iOS devices it is a special folder inside the application folder. @return The path to the app's folder for temporary files. */ + (NSString *_Nullable)temporaryPath; /** * Check if self has the given substring in case-sensitive * * @param substring The substring to be searched * * @return Returns YES if founded, NO if not */ - (BOOL)hasString:(NSString * _Nonnull)substring; /** * Check if self has the given substring specifying if is case-sensitive or not * * @param substring The substring to be searched * @param caseSensitive If the search has to be case-sensitive or not * * @return Returns YES if founded, NO if not */ - (BOOL)hasString:(NSString * _Nonnull)substring caseSensitive:(BOOL)caseSensitive; /** * Check if self is an email * * @return Returns YES if it's an email, NO if not */ - (BOOL)isEmail; /** * Check if the given string is an email * * @param email The string to be checked * * @return Returns YES if it's an email, NO if not */ + (BOOL)isEmail:(NSString * _Nonnull)email; /** * Convert a string to UTF8 * * @param string String to be converted * * @return Returns the converted string */ + (NSString * _Nonnull)convertToUTF8Entities:(NSString * _Nonnull)string; /** * Encode the given string to Base64 * * @param string String to encode * * @return Returns the encoded string */ + (NSString * _Nonnull)encodeToBase64:(NSString * _Nonnull)string; /** * Encode the given string to Base64 * * @return Returns the encoded string */ - (NSString * _Nonnull)encodeToBase64; /** * Decode the given Base64 to string * * @param string String to decode * * @return Returns the decoded string */ + (NSString * _Nonnull)decodeBase64:(NSString * _Nonnull)string; /** * Decode the given Base64 to string * * @return Returns the decoded string */ - (NSString * _Nonnull)decodeBase64; /** * Convert the given NSString to NSData * * @param string The NSString to be converted * * @return Returns the converted NSString as NSData */ + (NSData * _Nonnull)convertToNSData:(NSString * _Nonnull)string; /** * Convert self to a NSData * * @return Returns self as NSData */ - (NSData * _Nonnull)convertToNSData; /** * Conver self to a capitalized string. * Example: "This is a Test" will return "This is a test" and "this is a test" will return "This is a test" * * @return Returns the capitalized sentence string */ - (NSString * _Nonnull)sentenceCapitalizedString; /** * Returns a human legible string from a timestamp * * @return Returns a human legible string from a timestamp */ - (NSString * _Nonnull)dateFromTimestamp; /** * Encode self to an encoded url string * * @return Returns the encoded NSString */ - (NSString * _Nonnull)urlEncode DEPRECATED_MSG_ATTRIBUTE("Use -URLEncode"); /** * Encode self to an encoded url string * * @return Returns the encoded NSString */ - (NSString * _Nonnull)URLEncode; /** * Remove double or more duplicated spaces * * @return String without additional spaces */ - (NSString * _Nonnull)removeExtraSpaces; /** * Returns a new string containing matching regular expressions replaced with the template string * * @param regexString The regex string * @param replacement The replacement string * * @return Returns a new string containing matching regular expressions replaced with the template string */ - (NSString * _Nonnull)stringByReplacingWithRegex:(NSString * _Nonnull)regexString withString:(NSString * _Nonnull)replacement; /** * Convert HEX string (separated by space) to "usual" characters string. * Example: "68 65 6c 6c 6f" -> "hello" * * @return Readable string */ - (NSString * _Nonnull)HEXToString; /** * Convert string to HEX string. * Example: "hello" -> "68656c6c6f" * * @return HEX string */ - (NSString * _Nonnull)stringToHEX; /** * Used to create an UUID as NSString * * @return Returns the created UUID string */ + (NSString * _Nonnull)generateUUID; /** * Returns if self is a valid UUID or not * * @return Returns if self is a valid UUID or not */ - (BOOL)isUUID; /** * Returns if self is a valid UUID for APNS (Apple Push Notification System) or not * * @return Returns if self is a valid UUID for APNS (Apple Push Notification System) or not */ - (BOOL)isUUIDForAPNS; /** * Converts self to an UUID APNS valid (No "<>" or "-" or spaces) * * @return Converts self to an UUID APNS valid (No "<>" or "-" or spaces) */ - (NSString * _Nonnull)convertToAPNSUUID; /** * Remove all white space * @return Returns string which remove all white space */ - (NSString *_Nullable)trimAllWhiteSpace; /** * Used to calculate text height for max width and font * * @param width Max width to fit text * @param font Font used in text * * @return Returns the calculated height of string within width using given font */ - (CGFloat)heightForWidth:(float)width andFont:(UIFont * _Nonnull)font; + (NSString *_Nullable)getAppName; @end