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

Re: [Clip] Re: splitting a string on a character

Expand Messages
  • Don Passenger
    Well done Hugo. Much easier than where I was going ... which was this direction: ;test rounddown (from earlier question) ^!Set %test%=^$Calc(floor(6.53+1))$
    Message 1 of 4 , Oct 3, 2004
      Well done Hugo. Much easier than where I was going ... which was this
      direction:

      ;test rounddown (from earlier question)
      ^!Set %test%=^$Calc(floor(6.53+1))$

      ^!Prompt ^%test%
      ;works


      ;test time split (this question)
      ^!Set %test2%=22:15
      ^!Prompt ^%test2%

      ;get index of :
      ^!Set %test3%=^$StrPos(":";"^%test2%";False)$
      ^!Prompt ^%test3%
      ;works

      ;get front part of string
      ^!Set %test4%=^$StrCopy("^%test2%";0;^$Calc(^%test3%-1)$)$
      ^!Prompt ^%test4%
      ;works

      ;get last part of string
      ^!Set %test5%=^$StrCopyRight("^%test2%";^$Calc(^%test3%+1)$)$
      ^!Prompt ^%test5%
      ;MISERABLE FAILURE

      ^!Continue stop here

      Think I'll use your method. Oddly, I don't yet have my question let
      alone any other answers, but your answer arrived fine. Odd how some
      things just seem to get lost for a while. Big system I guess over at
      yahoogroups.

      Hugo Paulissen wrote:

      >
      > --- In ntb-clips@yahoogroups.com, Don Passenger <dpasseng@i...> wrote:
      >
      >>the next part of my puzzle is splitting a string on a character
      >>in my case I am working with minutes:seconds (note : in the middle)
      >>I want to split the string on the : but there may be either one or
      >
      > two
      >
      >>minute characters
      >>
      >
      >
      > Don,
      >
      > You could look into all string functions or you could simply use an
      > array and do it like this...
      >
      > ^!SetListDelimiter :
      > ^!SetArray %time%=10:45
      > ^!Info ^%time1%
      > ^!Info ^%time2%
      >
      > Hugo
    • Alan
      Don Passenger wrote: [ . . ] ... Hugo has shared the equivalent: ^!SetListDelimiter : ^!SetArray my( @stuff ) = split( /:/,
      Message 2 of 4 , Oct 3, 2004
        Don Passenger wrote:
        [ . . ]
        > Perl has a split function that does this type of thing, but I am not
        > finding the equivalent.

        Hugo has shared the equivalent:

        ^!SetListDelimiter :
        ^!SetArray



        <Perl_Only_Associated>

        my( @stuff ) = split( /:/, $SomeDataString ) ;

        But if your char also is a *Perl* meta char (for example, just such as
        the pipe or | char is) then such meta char need be escaped (\ escapes,
        makes so is interpreted as a literal), thus:

        my( @stuff ) = split( /\|/, $SomeDataString ) ;

        Perl split does use a character as a delimiter then all item(s) between
        delimiter(s) are split off so to speak (or, put into an array).

        </Perl_Only_Associated>


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