Reg Ex Help for a Lazy VB Programmer

adams114_at_comcast.net
Date: 04/19/04

  • Next message: mdh: "Posting Credentials using LWP To WebMethods"
    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;
            }
            
    }


  • Next message: mdh: "Posting Credentials using LWP To WebMethods"

    Relevant Pages

    • Re: Prothon should not borrow Python strings!
      ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
      (comp.lang.python)
    • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
      ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
      (comp.programming)
    • Re: Fast UTF-8 strlen function
      ... >> Is there a fast UTF-8 string length function floating around? ... Length in bytes, or length in characters? ... For UTF-8, the main basic "change" you have to make to your string routines ... then I could individually look up the characters in my UNICODE ...
      (alt.lang.asm)
    • Re: Byte Array to String
      ... retrieved text will mismatch the original characters. ... encoding the characters. ... Dim strFileData as String ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: A note on personal corruption as a result of using C
      ... impossible to write effective string validation routines by definition ... (Note that a string literal may contain embedded null characters; ... without resorting to abusive language. ... In practice, programmers typically use "struct" ...
      (comp.programming)