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

Re: [PBML] splitting characters ?

Expand Messages
  • Gamaliel Lagman
    On Thu, 24 Aug 2000, Nathan Rimmer wrote: # Hi, # # # I am trying to find out how to perform a particular # split. # # I know I can split a variable by
    Message 1 of 3 , Aug 24, 2000
    • 0 Attachment
      On Thu, 24 Aug 2000, Nathan Rimmer wrote:

      #>Hi,
      #>
      #>
      #>I am trying to find out how to perform a particular
      #>split.
      #>
      #>I know I can split a variable by looking for a blank
      #>space.
      #>
      #>IE
      #>($ipaddress,$is,$unreachable)=split("
      #>",$errorpingresult);
      #>
      #>But what I want to do is to split a single word into
      #>its individual characters and then process it.
      #>
      #>IE
      #>split "wibble" into "w" "i" "b" "b" "l" and "e"
      #>
      #>I'm struggling on what to split on - ie I cant use
      #>blank spaces or | as I have done for other splits.
      #>
      #>
      #>Does anyone have any ideas ?
      #>

      Hi,

      Still use the basic split.

      @array = split //, $string;


      Split it witout any characters in between the slashes "//" it should
      segregate the characters from the string.

      ~gams
    • Tom Barron
      ... You can also get to individual characters in a string without creating an extra array with substr(): for ($idx = 0 ; $idx
      Message 2 of 3 , Aug 24, 2000
      • 0 Attachment
        Gamaliel Lagman wrote:
        >
        > On Thu, 24 Aug 2000, Nathan Rimmer wrote:
        > ...
        > #>But what I want to do is to split a single word into
        > #>its individual characters and then process it.
        > #>
        > #>IE
        > #>split "wibble" into "w" "i" "b" "b" "l" and "e"
        > #>
        > #>I'm struggling on what to split on - ie I cant use
        > #>blank spaces or | as I have done for other splits.
        > #>...
        > Still use the basic split.
        >
        > @array = split //, $string;
        >
        > Split it witout any characters in between the slashes "//" it should
        > segregate the characters from the string.

        You can also get to individual characters in a string without creating
        an extra array with substr():

        for ($idx = 0 ; $idx < length($string) ; $idx++)
        {
        $chr = substr($string,$idx,1);
        # do something with $chr
        }

        Tom
      Your message has been successfully submitted and would be delivered to recipients shortly.