06.09.2010, 09:43
Quote:
|
* AddLineBreaks(input[], chars=80)
This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string. pawn Code:
|

Try:
pawn Code:
stock
AddLineBreaks(input[], chars = 80)
{
new
Count = 1,
i = chars,
output[512];
format(output, sizeof(output), "%s", input);
while(output[i])
{
// if(i % chars) { printf("Loop: %d", i); } else { printf(" Start chars Index: %d", i); } // DEBUG
if(output[i] == ' ')
{
output[i] = '\n';
i = chars * (++Count);
} else i--;
}
return output;
}
pawn Code:
public
OnFilterScriptInit()
{
printf("%s", AddLineBreaks("This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string"));
printf("%s", AddLineBreaks("This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string", 20));
return 1;
}
Code:
[11:21:18] Start chars Index 80 [11:21:18] Loop: 79 [11:21:19] Loop: 78 [11:21:19] Loop: 77 [11:21:19] Loop: 76 [11:21:19] Start chars Index 160 [11:21:19] Loop: 159 [11:21:19] Start chars Index 240 [11:21:19] Loop: 239 [11:21:19] Start chars Index 320 [11:21:19] Loop: 319 [11:21:19] This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string [11:21:19] Start chars Index 20 [11:21:19] Loop: 19 [11:21:19] Loop: 18 [11:21:19] Loop: 17 [11:21:19] Loop: 16 [11:21:19] Start chars Index 40 [11:21:19] Loop: 39 [11:21:19] Loop: 38 [11:21:19] Loop: 37 [11:21:19] Loop: 36 [11:21:19] Start chars Index 60 [11:21:19] Loop: 59 [11:21:19] Loop: 58 [11:21:19] Loop: 57 [11:21:19] Loop: 56 [11:21:19] Start chars Index 80 [11:21:19] Loop: 79 [11:21:19] Loop: 78 [11:21:19] Loop: 77 [11:21:19] Loop: 76 [11:21:19] Start chars Index 100 [11:21:19] Start chars Index 120 [11:21:19] Loop: 119 [11:21:19] Loop: 118 [11:21:19] Loop: 117 [11:21:19] Start chars Index 140 [11:21:19] Loop: 139 [11:21:19] Loop: 138 [11:21:19] Loop: 137 [11:21:19] Loop: 136 [11:21:19] Start chars Index 160 [11:21:19] Loop: 159 [11:21:19] Start chars Index 180 [11:21:19] Start chars Index 200 [11:21:19] Loop: 199 [11:21:19] Start chars Index 220 [11:21:19] Loop: 219 [11:21:19] Loop: 218 [11:21:19] Loop: 217 [11:21:19] Loop: 216 [11:21:19] Loop: 215 [11:21:19] Loop: 214 [11:21:19] Loop: 213 [11:21:19] Loop: 212 [11:21:19] Loop: 211 [11:21:19] Start chars Index 240 [11:21:19] Loop: 239 [11:21:19] Start chars Index 260 [11:21:19] Loop: 259 [11:21:19] Start chars Index 280 [11:21:19] Loop: 279 [11:21:19] Loop: 278 [11:21:19] Loop: 277 [11:21:19] Loop: 276 [11:21:19] Loop: 275 [11:21:19] Start chars Index 300 [11:21:19] Loop: 299 [11:21:19] Loop: 298 [11:21:19] Loop: 297 [11:21:19] Loop: 296 [11:21:19] Loop: 295 [11:21:19] Loop: 294 [11:21:19] Loop: 293 [11:21:19] Start chars Index 320 [11:21:19] Loop: 319 [11:21:19] Start chars Index 340 [11:21:19] Loop: 339 [11:21:19] Loop: 338 [11:21:19] Loop: 337 [11:21:19] Loop: 336 [11:21:19] Loop: 335 [11:21:19] Loop: 334 [11:21:19] Loop: 333 [11:21:19] Start chars Index 360 [11:21:19] Loop: 359 [11:21:19] Start chars Index 380 [11:21:19] Loop: 379 [11:21:19] Loop: 378 [11:21:19] Loop: 377 [11:21:19] Loop: 376 [11:21:19] This function is meant to be used by DIALOG_STYLE_MSGBOX dialogs, when it is desired to show a large string, and this string to be split into several lines. It adds the line breaks just if it finds a ' ' (space) character. - Parameters: -- input[]: The string to be split. -- chars[]: How many minimum characters should show per line (default: 80). - Returns: -- The formatted string


