linux - how to replace a string in an efficient way in C -
i have string generated linux uuid generation code (libc):
1b4e28ba-2fa1-11d2-883f-b9a761bde3fb
i need replace of characters in string:
-
_
2
f
4
x
i generating 200 uuid
s using loop.
so every uuid need replace using custom function, function must maximum optimised so, how can attain that?
i suppose you're using char[] str
char *c; for(c = str; *c != '\0'; ++c){ if( *c == '-' ) *c = '_'; else if( *c == '2' ) *c = 'f'; else if( *c == '4' ) *c = 'x'; }
switch
version
char *c; for(c = str; *c != '\0'; ++c){ switch(*c){ case '-': *c = '_'; break; case '2': *c = 'f'; break; case '4': *c = 'x'; break; } }
Comments
Post a Comment