String Manipulation

Gilles G. schaouette at free.fr
Tue Jul 10 07:17:56 PDT 2007


Oups, sorry!
Of course you should use
RegExp(r"^.*href=\\\"(.*\.xsl).*$");
instead of
RegExp(^.*href=\\\"(.*\.xsl).*$);

(I Forgot the quotes _and_ the r in front of the RegExp to indicate that backslash must not be treated as an escape character...)

Regards.
--
Gilles

Gilles G. Wrote:

> Hello,
> maybe you can just use a regular expression...
> In D, this will give something like:
> import std.regexp;
> void main()
> {
>     char[] myStr = "...<?xml-stylesheet type=\"text/xsl\"href=\"example.xsl\"?>..."; 
>     // this is the first RegExp I found, it may be flawed... It assumes the xsl
>     // name has the extension ".xsl"
>     auto nameOfStyleSheetRe = new RegExp(^.*href=\\\"(.*\.xsl).*$);
>     auto m = nameOfStyleSheetRe.match(myStr);
>     // m[1] should now contain the string "example.xsl"
>     ... do what you want
> }
> okibi Wrote:
> 
> > Well, I ended up just doing some splits to get what the location of the xsl file will be. Still, I'd like someone to tell me if there is an easier way.
> > 
> > Thanks!
> > 
> > okibi Wrote:
> > 
> > > I have a question for you all.
> > > 
> > > If I have the following string or char[], how would I get the xsl filename out of it?
> > > 
> > > char[] myStr = "...<?xml-stylesheet type=\"text/xsl\" href=\"example.xsl\"?>...";
> > > 
> > > Is there a way to get it to return just example.xsl?
> > > 
> > > Thanks!
> > 
> 



More information about the Digitalmars-d-learn mailing list