AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cut String (https://forums.alliedmods.net/showthread.php?t=82281)

4JOKE 12-20-2008 10:31

Cut String
 
I need help with cutting strings.
I.E. : "This is my string" (without quotes)

And I need it to cut as here:
"this" " is my string"

I tryed it with strbreak, split or parse and it didn't functioned, because I still get:
"this" "is my string:

Does someone know how to solve my problem?

Thnx.

ConnorMcLeod 12-20-2008 11:22

Re: Cut String
 
strbreak is what you need.
http://www.amxmodx.org/funcwiki.php?...strb&go=search

All you have to do is add an extra space to the second part of the string.

This should work :
PHP Code:

new szFirst[16], szRest[64]
strbreak "This is my string"szFirstcharsmax(szFirst), szRest[1], charsmax(szRest)-


4JOKE 12-20-2008 11:45

Re: Cut String
 
Thnx, but your solution is not what I need.
There is no other way how to split string exatly as it is ? With spaces ?

Because I wanted to make scrolling text by show_hudmessage, so I need cut first char of string and put it to end.
I wanted to do it by strbreak() and format() but as I said I have problem with spaces when use strbreak().

SchlumPF* 12-20-2008 13:31

Re: Cut String
 
PHP Code:

stock first_char_to_last_char( const input[], output[] )
{    
    
formatoutputstrleninput ), "%s%s"input[1], input[0] );


example:
PHP Code:

new const string[64] = "abcdefghijklmnopqrstuvwxyz";
    
new 
temp[64];
first_char_to_last_charstringtemp );

// now temp[] stores this: "bcdefghijklmnopqrstuvwxyza" 


Exolent[jNr] 12-20-2008 13:34

Re: Cut String
 
Quote:

Originally Posted by SchlumPF* (Post 730434)
PHP Code:

stock first_char_to_last_char( const input[], output[] )
{    
    
formatoutputstrleninput ), "%s%s"input[1], input[0] );



PHP Code:

stock first_char_to_last_char( const input[], output[] )
{    
    
formatoutputstrleninput ), "%s%c"input[1], input[0] );



Emp` 12-20-2008 13:41

Re: Cut String
 
Quote:

Originally Posted by Exolent[jNr] (Post 730437)
PHP Code:

stock first_char_to_last_char( const input[], output[] )
{    
    
formatoutputstrleninput ), "%s%c"input[1], input[0] );



PHP Code:

stock move_chars( const input[], char_numoutput[] )
{    
    
formatexoutputstrleninput ), "%s%s"input[charnum], input );



SchlumPF* 12-20-2008 13:50

Re: Cut String
 
Quote:

Originally Posted by Exolent[jNr] (Post 730437)
PHP Code:

stock first_char_to_last_char( const input[], output[] )
{    
    
formatoutputstrleninput ), "%s%c"input[1], input[0] );



didnt know that pawn is able to print single chars by %c :/ never daw that one before

PHP Code:

stock first_char_to_last_char( const input[], output[], len )
{    
    
formatoutputlen"%s%c"input[1], input[0] );



4JOKE 12-20-2008 14:52

Re: Cut String
 
I didn't know it too :shock:

Thnx very much to all ! Problem solved :)


All times are GMT -4. The time now is 09:18.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.