I've used a regular expression to replace
http://example.com with <a
href="http://example.com">http://example.com</a>
But that is not what I want to do. I want to create a string array
like:
string[] bar = {"Some text ",
"http://www.google.com",
" more text ",
"fr*********@somewhere.com",
" more"}
It is not hard coded - i.e. text from a database table is stored in the
variable 'foo', which is then parsed to create a string array
resembling 'bar'
Then I use the iTextSharp PDF generator
Phrase p = new Phrase();
Chunk ch;
foreach(string baz in bar)
{
if(IsHyperLink(baz))
{
ch = new Chunk(baz,linkFont);
ch.SetAnchor(baz);
}
else if(IsEmail(baz))
{
ch = new Chunk(baz,linkFont);
ch.SetAnchor("mailto:" + baz);
}
else
{
ch = new Chunk(baz,normalFont);
}
p.Add(ch);
}
Chris Ballard wrote:
Sam,
Take a look at the docs for System.Text.RegularExpressions.Regex. iirc some
of the examples there show how to pick out URLs and email addresses.
If you havent looked at RegEx before, it is a very powerful class, and quite
easy to use once you get the hang of it.
--
Chris Ballard
MCSD.NET
"Sam Collett" wrote:
Say I have
string foo = "Some text http://www.google.com more text
fr*********@somewhere.com more";
How could I parse it to find the links and store the results in a
string array, i.e. to get
string[] bar = ParseText(foo);
// bar[0] = "Some text ", bar[1] = "http://www.google.com", bar[3] = "
more text ", bar[4] = "fr*********@somewhere.com", bar[5] = " more"
The string variable 'foo' will have much more text than this. I don't
expect many hyperlinks, and in some cases none (so there will be a
'bar[0]', but not 'bar[1]')