digitalmars.D - String & delimit
- =?ISO-8859-1?Q?Di=e9?= (13/13) Apr 03 2007 Hello
- Pragma (11/41) Apr 03 2007 First of all, the template uses Inline Function-Template Instantiation (...
- =?ISO-8859-1?Q?Di=e9?= (7/55) Apr 03 2007 Thank you Pragma,
- Frits van Bommel (2/3) Apr 03 2007 *Implicit* Function-Template Instantiation.
- Pragma (4/8) Apr 03 2007 D'oh. :(
- Chris Nicholson-Sauls (4/12) Apr 03 2007 No worries, I think in this case "Inline" makes a reasonable synonym. A...
- Gregor Kopp (9/9) Apr 03 2007 import std.string;
- Dan (6/16) Apr 03 2007 In good fun?? Good!
- Gregor Kopp (19/24) Apr 04 2007 I converted your pattern to a small d program:
- Frits van Bommel (6/21) Apr 04 2007 It's quite easy, in fact it's a one-character patch:
- Gregor Kopp (3/9) Apr 04 2007 Thank you for this info! Maybe this all helps Dié with his problem. Let...
- david (39/45) Apr 04 2007 Hello Dié,
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!
Apr 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: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
Apr 03 2007
Pragma Wrote:Dié wrote: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, byeHello 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: > 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
Apr 03 2007
Pragma wrote:Inline Function-Template Instantiation (IFTI)*Implicit* Function-Template Instantiation.
Apr 03 2007
Frits van Bommel wrote:Pragma wrote:D'oh. :( -- - EricAnderton at yahooInline Function-Template Instantiation (IFTI)*Implicit* Function-Template Instantiation.
Apr 03 2007
Pragma wrote:Frits van Bommel wrote:No worries, I think in this case "Inline" makes a reasonable synonym. And its easier to say. ;) -- Chris Nicholson-SaulsPragma wrote:D'oh. :(Inline Function-Template Instantiation (IFTI)*Implicit* Function-Template Instantiation.
Apr 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
Apr 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, GregorIn 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
Apr 03 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
Apr 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...
Apr 04 2007
Frits van Bommel schrieb: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...Thank you for this info! Maybe this all helps Dié with his problem. Lets hope so ;)
Apr 04 2007
Dié schrieb:Hello I have this string: blablabla thisis a string example <i_need_this_text>Hello Dié, did you get it worked out? If not: import std.regexp; int main(char[][] args) { char[] message = "just <a> few <tags>, no <nesting here>"; RegExp rg = new RegExp("<.*>", "g"); char[][] res = rg.match(message); assert(res[0] == "<a>"); assert(res[1] == "<tags>"); assert(res[2] == "<nesting here>"); // remove the delimiters foreach(inout v; res) v = v[1..$-1]; assert(res[0] == "a"); assert(res[1] == "tags"); assert(res[2] == "nesting here"); } If you need nesting (is this possible with RexExp? Found nothing...) you can use the function char[][] findNesting(char[] string, char left, char right) in the file (strex.d) I attached, which splits "this <test> is <advanced, as <you can> see>a<b<c>d>><e" in "test" "advanced, as <you can> see" "you can" "b<c>d" "c" (see test.d for examples) If you want correct nesting but only the innermost tags, apply the function bool containsTag(char[] string, char left, char right) also in the attached strex.d in combination with char[][] findNesting(char[] string, char left, char right) david
Apr 04 2007