Reg Ex Help for a Lazy VB Programmer
adams114_at_comcast.net
Date: 04/19/04
- Previous message: Ed: "forking socket server under Windows"
- Next in thread: Yaroslav: "Re: Reg Ex Help for a Lazy VB Programmer"
- Reply: Yaroslav: "Re: Reg Ex Help for a Lazy VB Programmer"
- Reply: nomercy: "Re: Reg Ex Help for a Lazy VB Programmer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 18 Apr 2004 18:16:45 -0700
Ok,
I'm trying to count the number of characters in a string. Once the
count of character's reaches x I want to replace the rest of the
string with an web site link. So here's what I've come up with so
far, but I cannot figure out how to do the replace. Can you help me? I
cannot even get what I have to compile.
sub replaceLink {
my ($text) = @_;
my $textLength;
my $url;
my $maxLength;
my $count;
my $newText;
$maxLength = 305;
$textLength = length $_;
$url = "<a href='somwhere.html'>[View Article]</a>";
if ($textLength > 305) {
$count = 0;
while ($text =~ .\g){ # this is the error, . matching
# any character, g for greed
$count++;
if ($count == $maxLength){
$newText = $newText . $url;
}
else {
$newText = $newText . $2;
}
}
return $newText;
}
else {
return $text;
}
}
- Previous message: Ed: "forking socket server under Windows"
- Next in thread: Yaroslav: "Re: Reg Ex Help for a Lazy VB Programmer"
- Reply: Yaroslav: "Re: Reg Ex Help for a Lazy VB Programmer"
- Reply: nomercy: "Re: Reg Ex Help for a Lazy VB Programmer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|