objective-c code to right pad a NSString?

前端 未结 6 1370
死守一世寂寞
死守一世寂寞 2020-12-06 01:26

Can someone give a code example of how to right pad an NSString in objective-c please?

For example want these strings:

Testing 123 Long String
Hello          


        
6条回答
  •  余生分开走
    2020-12-06 01:49

    Try below. its working for me.

    NSString *someString = @"1234";
    NSString *padded = [someString stringByPaddingToLength: 16 withString: @"x" startingAtIndex:0];
    
    NSLog(@"%@", someString);
    NSLog(@"%@", padded);
    

提交回复
热议问题