Raised This Month: $32 Target: $400
 8% 

Solved [INS] String copy after specific symbol or occurance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
raghava
Junior Member
Join Date: Jun 2016
Old 10-20-2017 , 12:07   [INS] String copy after specific symbol or occurance
Reply With Quote #1

Hi,

How to copy a strings upto specific symbol or its occurance.
example 85.153.157.227 or 192.168.1.1

I want to copy 85.153 or 192.168 to another variable how to do that.


Thanks
Raghava

Last edited by raghava; 10-22-2017 at 11:24. Reason: Issue Solved
raghava is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 10-20-2017 , 12:39   Re: [INS] String copy after specific symbol or occurance
Reply With Quote #2

Use ExplodeString() to breakup the string into a 2d array and Format() to format a string.

PHP Code:
char[] ip "127.0.0.1";

char buffer[4][32];
int splits ExplodeString(ip"."buffersizeof(buffer), sizeof(buffer[]));
if (
splits != 4)
    
ThrowError("Is not IPv4");
//Output:
//    buffer[0] = 127
//    buffer[1] = 0
//    buffer[2] = 0
//    buffer[3] = 1

char first[32];
char second[32];

Format(firstsizeof(first), "%s.%s"buffer[0], buffer[1]);
Format(secondsizeof(second), "%s.%s"buffer[2], buffer[3]);
//Output:
//    first = 127.0
//    second = 0.1 
Timocop is offline
raghava
Junior Member
Join Date: Jun 2016
Old 10-22-2017 , 11:24   Re: [INS] String copy after specific symbol or occurance
Reply With Quote #3

Thanks @Timocop
raghava is offline
Reply



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 15:57.


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