Loading ...
Sorry, an error occurred while loading the content.
 

Search & Replace to limit the number of characters

Expand Messages
  • joshua_g_2000
    Can some one help me with the search and replace function if I want to cut the number of characters in a variable e.g. $this = This is the variable that will
    Message 1 of 3 , Mar 27, 2002
      Can some one help me with the search and replace function if I want
      to cut the number of characters in a variable e.g.


      $this = "This is the variable that will hold the strings";

      $this =~ s///g; #EDIT THIS SEARCH AND REPLACE

      print "$this";

      Output:


      This is the vari...


      =======================================================

      The search and replace will cut the variable down to 15 characters
      (The first fifteen Characters) and add three dots at the end.

      Can anyone help???

      Joshua
    • webmaster_bmw
      ... ============================================================== Try using substr instead. =============================================================
      Message 2 of 3 , Apr 2, 2002
        --- In programming3@y..., joshua_g_2000 <no_reply@y...> wrote:
        > The search and replace will cut the variable down to 15 characters
        > (The first fifteen Characters) and add three dots at the end.
        ==============================================================
        Try using substr instead.
        =============================================================
      • dchoulette
        ... $string =~ s/^(.{15}).*/$1.../ if length($string) 15;
        Message 3 of 3 , Aug 21, 2002
          --- In programming3@y..., joshua_g_2000 <no_reply@y...> wrote:
          > ...
          > The search and replace will cut the variable down to 15 characters
          > (The first fifteen Characters) and add three dots at the end.
          > ...
          > Joshua

          $string =~ s/^(.{15}).*/$1.../ if length($string) > 15;
        Your message has been successfully submitted and would be delivered to recipients shortly.