User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,737 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 4596 | Replies: 25
Reply
Join Date: Apr 2007
Posts: 12
Reputation: MaestroS is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MaestroS MaestroS is offline Offline
Newbie Poster

PHP 'explode()' in C++ ?

  #1  
Apr 14th, 2007
Well, I wonder HOW to make an explode() function from PHP in C++

For those who don't know.

explode($separator, $string) breaks given $string through given $separator

for example:
$string = "Hello world!";
$result = explode(" ", $string);

echo $result[0]; //IT will give us HELLO word
echo $result[1]; //IT will give us WORLD! word

Each word is put into the array and has own index.

now... have someone any idea how to make it in C++ ?

Do not show any examples from this forum.
I already saw all and all are bad (doesn't match to the requirements)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: PHP 'explode()' in C++ ?

  #2  
Apr 14th, 2007
Well what have you tried? Show some effort.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: MaestroS is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MaestroS MaestroS is offline Offline
Newbie Poster

Re: PHP 'explode()' in C++ ?

  #3  
Apr 14th, 2007
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,774
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 330
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: PHP 'explode()' in C++ ?

  #4  
Apr 14th, 2007
PHP is open source. You can browse through its source code and see the way it is implemented.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Dec 2005
Posts: 3,257
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 20
Solved Threads: 368
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: PHP 'explode()' in C++ ?

  #5  
Apr 14th, 2007
> Both are not what I wanted to...
Great, out of all possible solutions, you've narrowed the field by two solutions.

Still leaves a hell of a lot of possible solutions out there.

Care to actually put some effort in towards showing what your ideal solution might be, rather than repeatedly posting "not it".

We're not here to guess what you're thinking, nor play "20 questions" to find such stuff out.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: MaestroS is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MaestroS MaestroS is offline Offline
Newbie Poster

Re: PHP 'explode()' in C++ ?

  #6  
Apr 14th, 2007
@Up

1. Get string wich user provided
2. break it through given separator
3. Each breaked put into array. Give to each word own index nr.
4. Each variable that function belongs to gives each word
e.x

char func = explode(char separator, char string);
cout func[0]; //1st word
cout func[1]; //2nd word

That's what you wanted ?
Reply With Quote  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: PHP 'explode()' in C++ ?

  #7  
Apr 14th, 2007
Is the separator a string or a char?
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,045
Reputation: vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light 
Rep Power: 9
Solved Threads: 157
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: PHP 'explode()' in C++ ?

  #8  
Apr 14th, 2007
you do not have to make one. it is available in libraries.
either the boost string algorithms or the boost tokenizer could be used.

here is an example using the boost string algorithms split. as you can notice, c++ libraries are
far more powerful and expressive. in this example, we are splitting on different criteria and placing the
result into different types of containers. and we are using one function: split to do all this.
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/lambda/lambda.hpp>
#include <vector>
#include <list>
#include <deque>
#include <algorithm>
using namespace std;
using namespace boost;
using namespace boost::lambda;

template<typename C> inline void print( const C& cntr )
{ for_each( cntr.begin(), cntr.end(), cout << constant('[') << _1 << "]  " ) ; }

int main()
{
  string str = "ab+*%cde4fg*hijk   lmno%+pqr3stu--vwx yz   "
                       "ab0cde+fgh2ij345klm4nop5qr7st" ;

  vector<string> vec ;
  split( vec, str, is_any_of("+*%-"), token_compress_on ) ; 
  print(vec) ; cout << '\n' ; 

  list<string> lst ;
  split( lst, str, is_from_range('2', '6') ) ; // token_compress_off by default
  print(lst) ; cout << '\n' ; 

  deque<string> deq ;
  split( deq, str, is_space(), token_compress_on ) ; 
  print(deq) ; cout << '\n' ; 
}
and this is the output:
g++ -Wall -std=c++98 -I/usr/local/include split.cpp ; ./a.out
[ab] [cde4fg] [hijk lmno] [pqr3stu] [vwx yz ab0cde] [fgh2ij345klm4nop5qr7st]
[ab+*%cde] [fg*hijk lmno%+pqr] [stu--vwx yz ab0cde+fgh] [ij] [] [] [klm] [nop] [qr7st]
[ab+*%cde4fg*hijk] [lmno%+pqr3stu--vwx] [yz] [ab0cde+fgh2ij345klm4nop5qr7st]


ps: i should qualify my first statement; you do not have to make one; unless your idea is to learn
programming.
Last edited by vijayan121 : Apr 14th, 2007 at 4:05 pm.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,663
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 16
Solved Threads: 297
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: PHP 'explode()' in C++ ?

  #9  
Apr 14th, 2007
I think he is too lazy to even try it himself. There is no way he will want to download the boost libraries being so lazy.

He just wants someone to code up the whole thing for him. He probably has no interest in c++.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Apr 2007
Posts: 12
Reputation: MaestroS is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MaestroS MaestroS is offline Offline
Newbie Poster

Re: PHP 'explode()' in C++ ?

  #10  
Apr 14th, 2007
I cannot do it myself, because I don't even know anything about (ok ok, i know basics) C++, because I'm a OBJECT programmer... clean C++ is for me ... like a miracle..

#iamthwee
The separator is a char
Last edited by MaestroS : Apr 14th, 2007 at 4:31 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:50 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC