Raised This Month: $ Target: $400
 0% 

Adding to String


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 03-12-2009 , 19:17   Adding to String
Reply With Quote #1

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"
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-12-2009 , 19:35   Re: Adding to String
Reply With Quote #2

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];
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Drak
Veteran Member
Join Date: Jul 2005
Old 03-12-2009 , 19:52   Re: Adding to String
Reply With Quote #3

The second one worked just fine, thanks.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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