Created
April 24, 2015 09:49
-
-
Save ziggi/7ad9abaa93f82154d58a to your computer and use it in GitHub Desktop.
Crop string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock crop_string(const input_str[], output_str[], const length = 60, const size = sizeof(output_str)) | |
{ | |
new | |
buffer[1024], | |
i = 0, | |
j = 0; | |
while (input_str[i] != '\0') { | |
if (i % length == 0) { | |
buffer[j] = '\n'; | |
buffer[j + 1] = input_str[i]; | |
j++; | |
} else { | |
buffer[j] = input_str[i]; | |
} | |
i++; | |
j++; | |
} | |
strmid(output_str, buffer, 0, size, size); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new string[] = "some long string"; | |
new result[128]; | |
crop_string(string, result); | |
print(string); | |
new string[128] = "some long string"; | |
crop_string(string, string); | |
print(string); | |
new string[128] = "some long string"; | |
crop_string(string, string, 2); | |
print(string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment