NSString金额","“.00”,手机号码“-”,

/**

 *  在金额字符串中加逗号

 *

 *  @param money money

 *

 *  @return moneyString

 */

- (NSString *)addDotInMoneyString:(NSString *)money {

if (money ==nil || money.length <1) {

returnnil;

}

NSString *fuhao =nil;

if ([moneyhasPrefix:@"-"]) {

fuhao = [moneysubstringToIndex:1];

money = [moneysubstringFromIndex:1];

}



if ([moneyisEqualToString:@"00"] || [moneyisEqualToString:@"000"]) {

money =@"0";

}


if (money.length >1 && [money hasPrefix:@"0"] && ![moneyhasPrefix:@"0."]) {

money = [NSStringstringWithFormat:@"%i", money.intValue];

}


if ([moneyhasPrefix:@"."]) {

money = [NSStringstringWithFormat:@"0%@", money];

}


/*t 用于临时接收money数据,防止moneyretain类型而改变值*/

NSMutableString *t = [NSMutableStringstringWithString:money];

[t replaceOccurrencesOfString:@","withString:@""options:NSBackwardsSearchrange:NSMakeRange(0, t.length)];

int lo = [trangeOfString:@"."].location;

if (lo >30000) lo = t.length;

int c = (lo -1) / 3;

for (int i =0; i < c; i++) {

lo -=3;

[t insertString:@","atIndex:lo];

}


if (fuhao.length >0)

return [fuhaostringByAppendingString:t];

   return t;

}


/**

 *  在手机号中间加横杆

 *

 *  @param phone phone

 *

 *  @return phoneString

 */

- (NSString *)addSeparatorInPhoneString:(NSString *)phone {

    

    NSString *temp = [phonestringByReplacingOccurrencesOfString:@"-"withString:@""];

temp = [temp stringByReplacingOccurrencesOfString:@" "withString:@""];

    

   NSString * regex = @"^[0-9]{0,11}$";

   NSPredicate *pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", regex];

   BOOL isMatch = [pred evaluateWithObject:temp];

    

   if (!isMatch) {

       static constNSString *number=@"0123456789";

        NSMutableString* mutableStr=[NSMutableStringstring];

       for (int i=0; i<temp.length; i++) {

           NSString* charStr=[temp substringWithRange:NSMakeRange(i, 1)];

           if ([number containString:charStr]) {

                [mutableStrappendString:charStr];

            }

        }

        temp=mutableStr;

    }

   if ([temp hasPrefix:@"86"])

        temp=[tempsubstringFromIndex:2];

    

   if(temp.length>3){

        temp = [[[temp substringToIndex:3]stringByAppendingString:@"-"]stringByAppendingString:[tempsubstringFromIndex:3]];

       if (temp.length>8) {

            temp = [[[temp substringToIndex:8]stringByAppendingString:@"-"]stringByAppendingString:[tempsubstringFromIndex:8]];

        }

    }

return temp;

}


//在账号中间加上空格

- (NSString *)addBlankInAccountString:(NSString *)string {

NSMutableString *temp = [NSMutableStringstringWithString:[string stringByReplacingOccurrencesOfString:@" "withString:@""]];

if (!temp || !temp.length || temp.length < 14) {

return string;

}


int index =0;

while (1) {

index +=4;

if (index < temp.length) {

[tempinsertString:@" "atIndex:index];

index +=1;

}

else {

break;

}

}

return temp;

}


- (void)SRKeyboardConfirmButtonPressed:(id)keyboard {

}


/**

 *  用户默认的getset方法,关联手机号,以便区分用户

 *

 *  @param object object

 *  @param key    key

 */

- (void)setObject:(id)object toUserDefaultForKey:(NSString *)key {

if (!key || !key.length) {

return;

}

NSUserDefaults *def = [NSUserDefaultsstandardUserDefaults];

NSString *phone = [defobjectForKey:LAST_LOGIN_PHONE_KEY];


if (!phone || !phone.length) {

return;

}


[def setObject:objectforKey:[phone stringByAppendingString:key]];

}





----------------------------------------去“空格”,去“,”

NSString *phoneString = [phone.textstringByReplacingOccurrencesOfString:@"-"withString:@""];

temp = [temp stringByReplacingOccurrencesOfString:@" "withString:@""];





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值