Split string
#1

How can i split a string to go onto a new line after a certain amount of characters.
Ex:
Код:
Hello guys how are you doing today its nice weather huh? this is used with textdraws.
Shows as:
Код:
Hello guys how are you doing today
its nice weather huh?
this is used with textdraws.
But the code looks like:
Код:
Hello guys how are you doing today ~n~its nice weather huh?~n~ this is used with textdraws.
So basically after like 30 characters it uses a ~n~ and starts a new line.

(im using this with an announce command)
Reply
#2

Hmm, I've been wondering this as-well, just ******d it and it seems this might be a way to do it.

Strmid

If anyone knows how to use it to do something like this, I'd be interested as-well.

EDIT: First off, realize that I am not the best scripter.

I attempted scripting something like this.

I suppose something like this could be done (untested):
pawn Код:
if(strlen(stringhere) >= size-at-which-you-must-split-the-text) //If string "stringhere"'s string length is over "size-at-which-you-must-split-the-text", do the following:
{
    strmid(string, stringhere, size-at-which-you-must-split-the-text, textsizeend);//Split string, extract beginning at size-at-which-you-must-split-the-text, and the end of textsizeend, and store it in the variable "string"
    strdel(stringhere, size-at-which-you-must-split-the-text, textsizeend); //Delete the second part from the string "stringhere", to prevent it from the text being there twice
    format(string, sizeof(string), "%s~n~%s", stringhere, string);//Format the string with the ~n~ inbetween the two strings
    //Do whatever with string now
}
Hope I explained it good enough

EDIT2:

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
for(new i = 30, j = strlen(text); i < j; i += 30)
{
    strins(text, "~n~", i);
}
Something like that, maybe. Untested.
This actually seems more efficient then my code, and actually makes sense.

It simply makes 2 new variables, one is 30, while the other is the length of the text that is inputted. Then, if the text is greater than 30 (string length), it will add a ~n~ at the mark.

Then again, I'd also suggest checking where the closest space is, cause I wouldn't like to see this happen.

Код:
/testcommand Testing out my sick thing... blabla... (20+ characters later) blablablatestbla
And then it output like so:

Код:
Testing out my sick thing... blabla... blablabl
atestbla
Reply
#3

pawn Код:
for(new i = 30, j = strlen(text); i < j; i += 30)
{
    strins(text, "~n~", i);
}
Something like that, maybe. Untested.
Reply
#4

pawn Код:
MultiLineString(string[], charactersPerLine = 30, separator[5] = "~n~")
{
    for(new i = charactersPerLine, len = strlen(string); i + 30 < len; i += 30)
    {
        strins(string, separator, i);
    }

    return string;
}
Untested.

Use:

pawn Код:
GameTextForAll(MultiLineString("hi my name is bob and i ride a little pony whos name is my little pony and i like making love to it"), 3000, 5);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)