AlliedModders

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

Drak 03-12-2009 19:17

Adding to String
 
If I have a string like such:
Code:
new String[7] = "123456"
How can I easily add a "-" in the center of the string, to make it like so:
Code:
// String would contain "123-456"

Emp` 03-12-2009 19:35

Re: Adding to String
 
Code:

new szFirst[7];
copy( szFirst, 6, String );

new location = contain( szFirst, "3");
if( location != -1 )
  szFirst[location+1] = 0;

format( String, 6, "%s-%s", szFirst, String[location+1] );

Can't really think of a better way to do it. Need a little more information on what you really want.

Could also do something like:
Code:

new szCopy[7];
for( new i; i<sizeof String; i++ ){
  if( i == desired_location )
    szCopy[i++] = '-';
  szCopy[i] = String[i];
}


Drak 03-12-2009 19:52

Re: Adding to String
 
The second one worked just fine, thanks. :D


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

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