Git Product home page Git Product logo

strconduct's Introduction

StrConduct

字符串处理 去除指定字符串两边空格 有个朋友问的 帮他写的 顺带分享给大家

#import "ViewController.h"

#define YOURSTR @"str"

@interface ViewController ()

@end

@implementation ViewController

  • (void)viewDidLoad {

    [super viewDidLoad];

    NSString *str = @"去 掉 空 格 str 看 看";

    NSLog(@"处理前:%@",str);

    NSLog(@"处理后:%@",[self stringConductWithStr:str]);

}

  • (NSString *)stringConductWithStr:(NSString *)str{

    NSMutableString *mulStr = [[NSMutableString alloc] initWithString:str];

    if ([str containsString:YOURSTR]) {

     NSRange range = [mulStr rangeOfString:YOURSTR];
     
     if (range.location >= 1 
     && [[mulStr substringWithRange:NSMakeRange(range.location - 1, 1)] isEqualToString:@" "] 
     && [[mulStr substringWithRange:NSMakeRange(range.location + range.length, 1)] isEqualToString:@" "]) {
     
          [mulStr replaceCharactersInRange:NSMakeRange(range.location - 1, range.length + 2) withString:YOURSTR];
          
      }
    

    }

    return [NSString stringWithFormat:@"%@",mulStr];

}

@end

strconduct's People

Contributors

glh239 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.