Jump to page: 1 2
Thread overview
String & delimit
Apr 03, 2007
Dié
Apr 03, 2007
Pragma
Apr 03, 2007
Dié
Apr 03, 2007
Frits van Bommel
Apr 03, 2007
Pragma
Apr 03, 2007
Gregor Kopp
Apr 03, 2007
Dan
Apr 04, 2007
Gregor Kopp
Apr 04, 2007
Frits van Bommel
Apr 04, 2007
Gregor Kopp
Apr 04, 2007
david
April 03, 2007
Hello

I have this string:

blablabla thisis a string example <i_need_this_text>

With Tango.text.Util i think i can use "delimit" function for extracting the test "i_need_this_text".

delimit("blablabla thisis a string example <i_need_this_text>","<>")

But i found in http://www.dsource.org/projects/tango/docs/current/tango.text.Util.html

the delimit declaration:

T[][] delimit (T)(T[] src, T[] set);

and now how can i correctly use this function with template? I suppose i must declare e template like this

template TText(T){alias T* t;}

but i dont understand how use the template with the delimit function.

Someone can explain me?
Thank you!

April 03, 2007
Dié wrote:
> Hello
> 
> I have this string:
> 
> blablabla thisis a string example <i_need_this_text>
> 
> With Tango.text.Util i think i can use "delimit" function for extracting the test "i_need_this_text".
> 
> delimit("blablabla thisis a string example <i_need_this_text>","<>")
> 
> But i found in http://www.dsource.org/projects/tango/docs/current/tango.text.Util.html
> 
> the delimit declaration:
> 
> T[][] delimit (T)(T[] src, T[] set);
> 
> and now how can i correctly use this function with template? I suppose i must declare e template like this
> 
> template TText(T){alias T* t;}
> 
> but i dont understand how use the template with the delimit function.
> 
> Someone can explain me?
> Thank you!
> 

First of all, the template uses Inline Function-Template Instantiation (IFTI); the compiler will *deduce* what 'T' is based on the arguments you pass to delimit().  Just call it like "delimit(string1,string2)" and it'll work fine.

Second, let's look at the documentation for the delimit() function:

> # T[][] delimit (T)(T[] src, T[] set);
>     Split the provided array wherever a delimiter-set instance is found,
> and return the resultant segments. The delimiters are excluded from
> each of the segments. Note that delimiters are matched as a set of
> alternates rather than as a pattern.

Arguably, this is not the best description in the world.  It makes much more sense after seeing an example of what it does:

auto x = delimit("One,Two;Three.Four&Five",",;.&");

The variable x will now be an array of strings, containing "One","Two","Three","Four", and "Five" in that order.  It's important to note that the second argument of the delimit() function is used as a series of single-character delimiters that are used to split up the source string.  The delimiters themselves are not returned.

-- 
- EricAnderton at yahoo
April 03, 2007
import std.string;
import std.stdio;
void main()
{writefln(split(split(
"blablabla thisis a string example <i_need_this_text> ole!"
, "<")[1],">")[0]);}


SCNR!!!
Maybe a Regex would be better, if you just want to do textprocessing?

in good fun, Gregor
April 03, 2007
Pragma Wrote:

> Dié wrote:
> > Hello
> > 
> > I have this string:
> > 
> > blablabla thisis a string example <i_need_this_text>
> > 
> > With Tango.text.Util i think i can use "delimit" function for extracting the test "i_need_this_text".
> > 
> > delimit("blablabla thisis a string example <i_need_this_text>","<>")
> > 
> > But i found in http://www.dsource.org/projects/tango/docs/current/tango.text.Util.html
> > 
> > the delimit declaration:
> > 
> > T[][] delimit (T)(T[] src, T[] set);
> > 
> > and now how can i correctly use this function with template? I suppose i must declare e template like this
> > 
> > template TText(T){alias T* t;}
> > 
> > but i dont understand how use the template with the delimit function.
> > 
> > Someone can explain me?
> > Thank you!
> > 
> 
> First of all, the template uses Inline Function-Template Instantiation (IFTI); the compiler will *deduce* what 'T' is based on the arguments you pass to delimit().  Just call it like "delimit(string1,string2)" and it'll work fine.
> 
> Second, let's look at the documentation for the delimit() function:
> 
>  > # T[][] delimit (T)(T[] src, T[] set);
>  >     Split the provided array wherever a delimiter-set instance is found,
>  > and return the resultant segments. The delimiters are excluded from
>  > each of the segments. Note that delimiters are matched as a set of
>  > alternates rather than as a pattern.
> 
> Arguably, this is not the best description in the world.  It makes much more sense after seeing an example of what it does:
> 
> auto x = delimit("One,Two;Three.Four&Five",",;.&");
> 
> The variable x will now be an array of strings, containing "One","Two","Three","Four", and "Five" in that order.  It's important to note that the second argument of the delimit() function is used as a series of single-character delimiters that are used to split up the source string.  The delimiters themselves are not returned.
> 
> -- 
> - EricAnderton at yahoo

Thank you Pragma,

before posting my problem i have read the doc. and i have tried with

"delimit(string1,string2)"  (directly with char type)

but after your post i think my problem is another....

mmm i wont to discover this new problem now!

Thank you, bye
April 03, 2007
Pragma wrote:
> Inline Function-Template Instantiation (IFTI)

*Implicit* Function-Template Instantiation.
April 03, 2007
Frits van Bommel wrote:
> Pragma wrote:
>> Inline Function-Template Instantiation (IFTI)
> 
> *Implicit* Function-Template Instantiation.

D'oh.  :(

-- 
- EricAnderton at yahoo
April 03, 2007
Gregor Kopp Wrote:

> import std.string;
> import std.stdio;
> void main()
> {writefln(split(split(
> "blablabla thisis a string example <i_need_this_text> ole!"
> , "<")[1],">")[0]);}
> SCNR!!!
> Maybe a Regex would be better, if you just want to do textprocessing?
> 
> in good fun, Gregor

In good fun??  Good!

In JavaScript, I think I write it something like:

"blablabla thisis a string example <i_need_this_text> ole!".match(
/<([^>]+)>/m)[1];

I haven't done any web data mining for a while now, so I can't remember what [#] to use for first sub-match.  : p
April 03, 2007
Pragma wrote:
> Frits van Bommel wrote:
>> Pragma wrote:
>>> Inline Function-Template Instantiation (IFTI)
>>
>> *Implicit* Function-Template Instantiation.
> 
> D'oh.  :(
> 

No worries, I think in this case "Inline" makes a reasonable synonym.  And its easier to say.  ;)

-- Chris Nicholson-Sauls
April 04, 2007
Dan schrieb:
> In JavaScript, I think I write it something like:
> 
> "blablabla thisis a string example <i_need_this_text> ole!".match(
> /<([^>]+)>/m)[1];
> 

I converted your pattern to a small d program:

---begin
import std.stdio;
import std.regexp;
void main()
{
auto s = "blablabla thisis a string example <i_need_this_text> ole!";
auto m = std.regexp.search(s, "<([^>]+)>");
if (m) writefln("%s", m.match(0));
}
---end

which prints <i_need_this_text>

I don't have time to take a closer look at your pattern so that it prints only i_need_this_text. I always get headache on Regexp ;)

greets, Gregor

ps.: have found it at [1] and [2]

[1] http://www.digitalmars.com/d/regular-expression.html
[2] http://www.digitalmars.com/d/phobos/std_regexp.html
April 04, 2007
Gregor Kopp wrote:
> ---begin
> import std.stdio;
> import std.regexp;
> void main()
> {
> auto s = "blablabla thisis a string example <i_need_this_text> ole!";
> auto m = std.regexp.search(s, "<([^>]+)>");
> if (m) writefln("%s", m.match(0));
> }
> ---end
> 
> which prints <i_need_this_text>
> 
> I don't have time to take a closer look at your pattern so that it prints only i_need_this_text. I always get headache on Regexp ;)

It's quite easy, in fact it's a one-character patch:
	if (m) writefln("%s", m.match(1));

A parameter > 0 passed to match(int) returns the part that matches the corresponding pair of parentheses, and the correct subexpression was already parenthesized...
« First   ‹ Prev
1 2