objective-c right padding

后端 未结 3 476
南方客
南方客 2021-01-27 17:38

hello all hope someone can help with that. I was browsing the net and nothing really seems to make sense :S

so I have a string lets say: \"123\" and I would

3条回答
  •  礼貌的吻别
    2021-01-27 17:54

    NSMutableString* padString(NSString *str, int padAmt, char padVal)
    {
        NSMutableString *lol = [NSMutableString stringWithString:str];
    
        while (lol.length < padAmt) {
            [lol appendFormat:@"%c", padVal];
         }
    
        return lol;
    
    }
    

    And the Call

    int main(int argc, const char * argv[]) {
        @autoreleasepool {
    
    
            NSLog(@"%@", padString(@"123", 5, 'x'));
    
    
        }
        return 0;
    }
    

提交回复
热议问题