Skip to content

Instantly share code, notes, and snippets.

@ziggi
Created April 24, 2015 09:49
Show Gist options
  • Save ziggi/7ad9abaa93f82154d58a to your computer and use it in GitHub Desktop.
Save ziggi/7ad9abaa93f82154d58a to your computer and use it in GitHub Desktop.
Crop string
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);
}
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