Is there something like a split funcion in VB? I need it to split up an IP adress into an int array.
THNX!!!!
Printable View
Is there something like a split funcion in VB? I need it to split up an IP adress into an int array.
THNX!!!!
owyeah i forgot, no MFC please....thnx
i got the following errors when i tried to use that function:
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2065: 'string' : undeclared identifier
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2297: '&' : illegal, right operand has type 'class ios &(__cdecl *)(class ios &)'
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2065: 'separators' : undeclared identifier
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2065: 'list' : undeclared identifier
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2065: 'words' : undeclared identifier
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : warning C4804: '>' : unsafe use of type 'bool' in operation
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2446: '>' : no conversion from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(29) : error C2040: '>' : 'int' differs in levels of indirection from 'int *'
c:\documents and settings\jeffno\desktop\keyboardinput_win32\darkside web server\source.cpp(30) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
Error executing cl.exe.
anyone know why?
Put the header file "string" and also include
using namespace std
maybe you could take a look at this code. It takes a string and splits it up by looking for spaces. The last char should be an enter too in order for it to work.
char * SplitString(char * string, int size, int part)
{
int Spaces[255];
int j=0,h=0,l=0;
int temp;
char * ReturnString;
for(int i = 0; i < size; i++)
{
if (string[i] == ' '){
Spaces[j]=i;
j++;
}
}
if (part == 0) {
ReturnString = new char[Spaces[0] + 1];
for(h = 0; h < Spaces[0]; h++)
{
ReturnString[h] = string[h];
}
if (h == 0) {return "";}
ReturnString[h] = '\0';
}
else {
i = Spaces[part] - Spaces[part-1];
h = 0;
ReturnString = new char[i];
for(h = 0; h+1 < i; h++){
ReturnString[h] = string[Spaces[part-1]+ h + 1];
}
if (h == 0) {return "";}
ReturnString[h] = '\0';
}
return ReturnString;
}
I made it so there could be some little bugs in it but i haven't found 1 yet.
The function that was given earlier is better because it uses C++, not C...
PHP Code:#include <iostream.h>
#include <string.h>
int main()
{
char vHello[] = "Hello Internet World";
char * token;
char * nHello;
// This will copy the string into a new variable.
// Its a good idea to do this because the actual string
// gets modified by the string function.
nHello = new char[strlen(vHello) + 1]; // Make room for the null
strcpy(nHello, vHello); // Copy String
// This is your built in split function in c++ that will split by a char.
// This more or less grabs the first part of the string and stores it into token,
// then you have call it again to get the rest of it.
token = strtok(nHello, " ");
while (token != NULL) // Do until we have nothing left =P
{
cout << token << endl;
// We using the same string so we dont wanna pass anything.
token = strtok(NULL, " ");
}
delete [] nHello;
return 0;
}
Nooooo not strtok...it's evil! :mad:
=). I agree, though, strtok is evil =).Quote:
Originally posted by parksie
strtok is okay as long as you know what you've passed into it, and you don't call it on two different strings before you've finished with them.
Z.
Where'd I post that? :p :confused: :D
Why not use boost::tokenizer?Quote:
=). I agree, though, strtok is evil =).
Example:
The output is:PHP Code:// char_sep_example_1.cpp
#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>
int main()
{
std::string str = ";;Hello|world||-foo--bar;yow;baz|";
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep("-;|");
tokenizer tokens(str, sep);
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
std::cout << "<" << *tok_iter << "> ";
std::cout << "\n";
return 0;
}
Code:<Hello> <world> <foo> <bar> <yow> <baz>
I already do, and have done for a long while now ;)Quote:
Well, that is when I don't need the advanced features of my own tokeniser (grouping, etc.) -- once I write the correct functor for the boost one I can move over to that for everything.
You didn't mention that <string.h> is evil.
The standard headers (iostream, string etc) have NO extension.
#include <string> !!!!
#include <iostream> !!!!
using namespace std; !!!!
(I know it is an old post... But...)
Why doesn't this code work when I copy and paste it in VC++ compiler?
It says boost/tokenizer does not exist.. :(
www.boost.org
Download the library from there. You don't actually need to run the build instructions, just add C:\boost_1_30_0 or whatever to VC++'s include directories.
You only need to build parts of it if you need them, such as the regexps, threads, etc. The tokenisers are all wholly templated.