Hello,
I've been searching for some way to get all possible substrings out of
an input string. I've found information and scripts on suffix trees,
but the examples I found only return an array of suffixes (hence the
name I guess)...that is, substrings from progressively splitting off
an initial letter from the string. Has anyone run across a C++
implementation of perl's String::Splitter function? That's the kind
of functionality that I'm looking for.
Thanks,
Robert
|
|
0
|
|
|
|
Reply
|
nebnetjeruiti (1)
|
1/26/2010 12:14:26 AM |
|
On 26 =D1=8F=D0=BD=D0=B2, 03:14, Robert Reno <nebnetjeru...@gmail.com> wrot=
e:
> Hello,
>
> I've been searching for some way to get all possible substrings out of
> an input string.
Something like this:
$fullLength=3Dstrlen($string);
for($begin=3D0;$begin<$fullLength;++$begin)
for($l=3D$fullLength-$begin;$l>0;--$l)
echo substr($string,$begin,$l)."\n";
|
|
0
|
|
|
|
Reply
|
crimaniak
|
1/26/2010 8:04:32 AM
|
|
On 26 =D1=8F=D0=BD=D0=B2, 11:04, "criman...@googlemail.com"
<criman...@googlemail.com> wrote:
> Something like this:
>
> $fullLength=3Dstrlen($string);
> for($begin=3D0;$begin<$fullLength;++$begin)
> =C2=A0for($l=3D$fullLength-$begin;$l>0;--$l)
> =C2=A0 echo substr($string,$begin,$l)."\n";
Oh, no! I was in PHP conference now and this is result. %-)
|
|
0
|
|
|
|
Reply
|
crimaniak
|
1/26/2010 8:08:27 AM
|
|
On Jan 26, 9:14=A0am, Robert Reno <nebnetjeru...@gmail.com> wrote:
> Hello,
>
> I've been searching for some way to get all possible substrings out of
> an input string. =A0I've found information and scripts on suffix trees,
> but the examples I found only return an array of suffixes (hence the
> name I guess)...that is, substrings from progressively splitting off
> an initial letter from the string. =A0Has anyone run across a C++
> implementation of perl's String::Splitter function? =A0That's the kind
> of functionality that I'm looking for.
Have a look at boost's tokenize library.
Cheers,
Tony
|
|
0
|
|
|
|
Reply
|
tonydee
|
1/26/2010 8:32:52 AM
|
|
Robert Reno wrote:
> I've been searching for some way to get all possible substrings out of
> an input string. I've found information and scripts on suffix trees,
> but the examples I found only return an array of suffixes (hence the
> name I guess)...that is, substrings from progressively splitting off
> an initial letter from the string. Has anyone run across a C++
> implementation of perl's String::Splitter function? That's the kind
> of functionality that I'm looking for.
I'm not sure I understood you correctly -- is this what you need?
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
typedef std::vector<std::string> substrVector;
typedef std::pair<substrVector, substrVector> substrHelperType;
class Prepend : public std::unary_function<std::string, std::string> {
private: std::string prefix_;
public:
Prepend(const std::string &prefix): prefix_(prefix) {}
std::string operator() (const std::string &str) {
return prefix_ + str;
}
};
substrHelperType substringsHelper(const std::string &str) {
size_t len = str.length();
assert(len > 0);
std::string x(str.begin(), str.begin() + 1);
if (len > 1) {
substrHelperType rest =
substringsHelper(std::string(str.begin() + 1, str.end()));
substrVector p(1, x), np(rest.first);
p.resize(rest.first.size() + 1);
std::transform(rest.first.begin(), rest.first.end(),
p.begin() + 1, Prepend(x));
np.resize(np.size() + rest.second.size());
std::copy(rest.second.begin(), rest.second.end(),
np.end() - rest.second.size());
return substrHelperType(substrVector(p), substrVector(np));
} else {
return substrHelperType(substrVector(1, x), substrVector());
}
}
substrVector substrings(const std::string &str) {
substrHelperType res = substringsHelper(str);
res.first.resize(res.first.size() + res.second.size());
std::copy(res.second.begin(), res.second.end(),
res.first.end() - res.second.size());
return substrVector(res.first);
}
--
P. Lepin
|
|
0
|
|
|
|
Reply
|
P
|
1/28/2010 12:46:47 PM
|
|
|
4 Replies
796 Views
(page loaded in 0.074 seconds)
Similiar Articles: concatenate multiple strings - comp.lang.awkHow to get all possible substrings - comp.lang.c++... for some way to get all possible substrings out of an input string. I ... concatenate data from multiple fields into ... Extract first letter from a given string - comp.lang.awk ...How to get all possible substrings - comp.lang.c++ Extract first letter from a given string - comp.lang.awk ... How to get all possible substrings ... extracting from Any ... Replacing ONLY the first occurence of a substring in a string ...I can not work out how to do this as replace changes all occurrences. eg Field ... imagine it will be something like set field1= IF(POS(field1,','), CONCAT(substr ... How to get only numbers from a row using match() and regex? - comp ...Match returns the column where the first token is found and the length of the found "substring". This is the regex I used: where = match($0, "[0-9]{1,3}" But this ... How to get a String? - comp.soft-sys.matlabHow to get all possible substrings - comp.lang.c++ Hello, I've been searching for some way to get all possible substrings out of an input string. TLS negotiation - comp.mail.miscYou need to be able to get all 256 possible binary octets into the TELNET program. You also need to recognize all 256 possible binary octets. How to estimate exectution time - comp.soft-sys.matlabHow to get all possible substrings - comp.lang.c++ How to estimate exectution time - comp.soft-sys.matlab There is no program that can examine a second program and, in a ... Copy String from Sting - comp.soft-sys.matlabHow to get all possible substrings - comp.lang.c++... ve been searching for some way to get all possible substrings out of an input string. ... From what I have been ... API, get all dimensions aligned to selected dimension - comp.cad ...How to get all possible substrings - comp.lang.c++ API, get all dimensions aligned to selected dimension - comp.cad ..... that is aligned to the selected dimension, seems ... Find all possible pairs - comp.lang.prologHow to get all possible substrings - comp.lang.c++ boost multi index - possible? - comp.lang.c++.moderated How to modify so that i can get say all entries corresponding to ... C# Substring Examples - Dot Net PerlsThe second parameter is considered the largest possible, meaning the substring ends at the last char. Example program that calls Substring [C#] using System; class Program ... string::substr - C++ Reference - cplusplus.com - The C++ Resources ...This substring is the character sequence that starts at character position pos and has ... npos is a static member constant value with the greatest possible value for an ... 7/24/2012 5:11:26 AM
|