parse string to display items

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dropstengel

    #1

    parse string to display items

    Hi,

    I have a string that contains n items. Each item start with a '@' and the
    item itself does not contains the '@a'.
    For example the string looks like: "@one@two@three @four"

    I have to output this string as "one, two, three and four".
    So in fact the first '@' can be removed, the next except the last replaces
    by ", " and the last one by the word "and ".
    Is there a simple way doing this?

    Frank


  • Evertjan.

    #2
    Re: parse string to display items

    Dropstengel wrote on 17 aug 2004 in comp.lang.javas cript:
    [color=blue]
    > Hi,
    >
    > I have a string that contains n items. Each item start with a '@' and
    > the item itself does not contains the '@a'.
    > For example the string looks like: "@one@two@three @four"
    >
    > I have to output this string as "one, two, three and four".
    > So in fact the first '@' can be removed, the next except the last
    > replaces by ", " and the last one by the word "and ".
    > Is there a simple way doing this?[/color]

    s = "@one@two@three @four"

    s = s.substr(1).spl it('@').join(', ').replace(/,([^,]+)$/,' and $1')

    alert(s)



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: parse string to display items

      Dropstengel <ik@haat.spam > wrote:

      Both your From and Reply-To addresses do not specify mailboxes which is
      aviolation of Internet/Usenet standards and disregarding the Netiquette
      s well as most certainly a violation of the Acceptable Use Policy of your
      service provider. You have been warned.
      [color=blue]
      > I have a string that contains n items. Each item start with a '@' and the
      > item itself does not contains the '@a'.[/color]
      ^^ Is this a typo?
      [color=blue]
      > For example the string looks like: "@one@two@three @four"
      >
      > I have to output this string as "one, two, three and four".
      > So in fact the first '@' can be removed, the next except the last replaces
      > by ", " and the last one by the word "and ".
      > Is there a simple way doing this?[/color]

      Assuming that the above is a typo:

      var
      s = "@one@two@three @four",
      i = s.lastIndexOf(" @");

      [s.substring(1, i).split("@").j oin(", "), s.substr(i + 1)].join(" and ")


      PointedEars
      --
      So, somebody DOES read these!

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: parse string to display items

        Dropstengel <ik@haat.spam > wrote:

        Both your From and Reply-To addresses do not specify mailboxes which is
        a violation of Internet/Usenet standards and disregarding the Netiquette
        as well as most certainly a violation of the Acceptable Use Policy of
        your service provider. You have been warned.
        [color=blue]
        > I have a string that contains n items. Each item start with a '@' and the
        > item itself does not contains the '@a'.[/color]
        ^^ Is this a typo?
        [color=blue]
        > For example the string looks like: "@one@two@three @four"
        >
        > I have to output this string as "one, two, three and four".
        > So in fact the first '@' can be removed, the next except the last replaces
        > by ", " and the last one by the word "and ".
        > Is there a simple way doing this?[/color]

        Assuming that the above is a typo:

        var
        s = "@one@two@three @four",
        i = s.lastIndexOf(" @");

        [s.substring(1, i).split("@").j oin(", "), s.substr(i + 1)].join(" and ")


        PointedEars
        --
        So, somebody DOES read these!

        Comment

        • Dropstengel

          #5
          Re: parse string to display items


          "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
          news:Xns9548CD6 8D6898eejj99@19 4.109.133.29...[color=blue]
          > Dropstengel wrote on 17 aug 2004 in comp.lang.javas cript:
          >[color=green]
          > > Hi,
          > >
          > > I have a string that contains n items. Each item start with a '@' and
          > > the item itself does not contains the '@a'.
          > > For example the string looks like: "@one@two@three @four"
          > >
          > > I have to output this string as "one, two, three and four".
          > > So in fact the first '@' can be removed, the next except the last
          > > replaces by ", " and the last one by the word "and ".
          > > Is there a simple way doing this?[/color]
          >
          > s = "@one@two@three @four"
          >
          > s = s.substr(1).spl it('@').join(', ').replace(/,([^,]+)$/,' and $1')
          >
          > alert(s)
          >
          >
          >
          > --
          > Evertjan.
          > The Netherlands.
          > (Please change the x'es to dots in my emailaddress)[/color]


          Evertjan, bedankt (thanks)
          Now I see that it is quit simple....
          It is an accident that I code something up in JavaScript...
          Frank


          Comment

          • Dropstengel

            #6
            Re: parse string to display items


            "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
            news:1467397.TW E2VrDqAf@Pointe dEars.de...[color=blue]
            > Dropstengel <ik@haat.spam > wrote:
            >
            > Both your From and Reply-To addresses do not specify mailboxes which is
            > a violation of Internet/Usenet standards and disregarding the Netiquette
            > as well as most certainly a violation of the Acceptable Use Policy of
            > your service provider. You have been warned.[/color]

            Do you warn everybody?
            [color=blue]
            >[color=green][color=darkred]
            > >>[/color][/color]
            >
            > PointedEars
            > --[/color]
            Frank


            Comment

            • Michael Winter

              #7
              Re: parse string to display items

              On Tue, 17 Aug 2004 21:08:07 +0200, Dropstengel <ik@haat.spam > wrote:

              [snipped drivel on munged addresses]
              [color=blue]
              > Do you warn everybody?[/color]

              Unfortunately, yes, he does. Most people just ignore it and move on to the
              useful things he says. I suggest you do the same. :)

              Mike

              --
              Michael Winter
              Replace ".invalid" with ".uk" to reply by e-mail

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: parse string to display items

                Dropstengel wrote:
                [color=blue]
                > "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message[color=green]
                >> Dropstengel <ik@haat.spam > wrote:
                >> Both your From and Reply-To addresses do not specify mailboxes which is
                >> a violation of Internet/Usenet standards and disregarding the Netiquette
                >> as well as most certainly a violation of the Acceptable Use Policy of
                >> your service provider. You have been warned.[/color]
                >
                > Do you warn everybody?[/color]

                Almost everybody who perpetrates this violation. If I take the time
                and the *continuing* behavior is also a violation of the Acceptable
                Use Policy of the respective service provider's AUP, the SP is informed
                about the case of network abuse in a formal complaint. The respective
                poster is always killfiled on NetNews with its invalid From (so that
                their postings are no longer filtered if they changed it to something
                that is in accordance with the Net's standards/the Netiquette).


                F'up2 PointedEars, Score adjusted
                --
                All I wanted was a little bit of time to myself. Then they started
                mozilla.org. Bastards.

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: parse string to display items

                  Dropstengel wrote:
                  [color=blue]
                  > "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message[color=green]
                  >> Dropstengel <ik@haat.spam > wrote:
                  >> Both your From and Reply-To addresses do not specify mailboxes which is
                  >> a violation of Internet/Usenet standards and disregarding the Netiquette
                  >> as well as most certainly a violation of the Acceptable Use Policy of
                  >> your service provider. You have been warned.[/color]
                  >
                  > Do you warn everybody?[/color]

                  Almost everybody who perpetrates this violation. If I take the time and
                  the *continuing* behavior is also a violation of the Acceptable Use Policy
                  of the respective service provider, the SP is informed about the case of
                  network abuse in a formal complaint. The respective posters are always
                  killfiled on NetNews with their invalid From (so that their postings are no
                  longer filtered if they changed it to something that is in accordance with
                  the Net's standards/the Netiquette).


                  F'up2 PointedEars, Score adjusted
                  --
                  All I wanted was a little bit of time to myself. Then they started
                  mozilla.org. Bastards.

                  Comment

                  • Dropstengel

                    #10
                    Re: parse string to display items


                    "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                    news:opscv5h7fh x13kvk@atlantis ...[color=blue]
                    > On Tue, 17 Aug 2004 21:08:07 +0200, Dropstengel <ik@haat.spam > wrote:
                    >
                    > [snipped drivel on munged addresses]
                    >[color=green]
                    > > Do you warn everybody?[/color]
                    >
                    > Unfortunately, yes, he does. Most people just ignore it and move on to the
                    > useful things he says. I suggest you do the same. :)
                    >[/color]

                    Yes, I'd love to..thanks.
                    [color=blue]
                    > Mike
                    >
                    > --
                    > Michael Winter
                    > Replace ".invalid" with ".uk" to reply by e-mail[/color]

                    Frank


                    Comment

                    • Randy Webb

                      #11
                      Re: parse string to display items

                      Dropstengel wrote:[color=blue]
                      > "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
                      > news:1467397.TW E2VrDqAf@Pointe dEars.de...
                      >[color=green]
                      >>Dropstengel <ik@haat.spam > wrote:
                      >>
                      >>Both your From and Reply-To addresses do not specify mailboxes which is
                      >>a violation of Internet/Usenet standards and disregarding the Netiquette
                      >>as well as most certainly a violation of the Acceptable Use Policy of
                      >>your service provider. You have been warned.[/color]
                      >
                      >
                      > Do you warn everybody?[/color]

                      Nah, he only warns those that he notices. And when pressed, he cites an
                      article that is outdated and totally rubbish. I have asked several times
                      (of him) to explain the difference between a From address that does not
                      specify a mailbox and a From address that specifies a mailbox that can
                      not recieve email. In either case, you can't email the person. I guess
                      he has never explained it because he can't grasp the simple idea "It
                      doesn't matter".

                      --
                      Randy
                      comp.lang.javas cript FAQ - http://jibbering.com/faq

                      Comment

                      • Dr John Stockton

                        #12
                        Re: parse string to display items

                        JRS: In article <41225789$0$211 06$e4fe514c@new s.xs4all.nl>, dated Tue,
                        17 Aug 2004 21:08:07, seen in news:comp.lang. javascript, Dropstengel
                        <ik@haat.spam > posted :[color=blue]
                        >
                        >"Thomas 'PointedEars' Lahn" <PointedEars@we b.de> wrote in message
                        >news:1467397.T WE2VrDqAf@Point edEars.de...[color=green]
                        >> Dropstengel <ik@haat.spam > wrote:
                        >>
                        >> Both your From and Reply-To addresses do not specify mailboxes which is
                        >> a violation of Internet/Usenet standards and disregarding the Netiquette
                        >> as well as most certainly a violation of the Acceptable Use Policy of
                        >> your service provider. You have been warned.[/color]
                        >
                        >Do you warn everybody?[/color]

                        Unfortunately, more or yes less. The Germans have not entirely lost the
                        offensive habits displayed in 1914 ff and 1933 ff.

                        IMHO, the nicer ones need to explain to Lahn the error of his ways.

                        --
                        © John Stockton, Surrey, UK. ???@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
                        Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.

                        In MS OE, choose Tools, Options, Send; select Plain Text for News and E-mail.

                        Comment

                        • Mick White

                          #13
                          Re: parse string to display items

                          Dropstengel wrote:
                          [color=blue]
                          > Hi,
                          >
                          > I have a string that contains n items. Each item start with a '@' and the
                          > item itself does not contains the '@a'.
                          > For example the string looks like: "@one@two@three @four"
                          >
                          > I have to output this string as "one, two, three and four".
                          > So in fact the first '@' can be removed, the next except the last replaces
                          > by ", " and the last one by the word "and ".
                          > Is there a simple way doing this?
                          >
                          > Frank
                          >
                          >[/color]
                          "@one@two@three @four".substrin g(1).split("@") .join(",")

                          Mick

                          Comment

                          • Shawn Milo

                            #14
                            Re: parse string to display items

                            "Dropstenge l" <ik@haat.spam > wrote in message news:<412247d7$ 0$78286$e4fe514 c@news.xs4all.n l>...[color=blue]
                            > Hi,
                            >
                            > I have a string that contains n items. Each item start with a '@' and the
                            > item itself does not contains the '@a'.
                            > For example the string looks like: "@one@two@three @four"
                            >
                            > I have to output this string as "one, two, three and four".
                            > So in fact the first '@' can be removed, the next except the last replaces
                            > by ", " and the last one by the word "and ".
                            > Is there a simple way doing this?
                            >
                            > Frank[/color]


                            The easiest way to do this, I think, is with a regex.
                            Then, do your split() as normal.

                            Shawn

                            Tested code:

                            <script type="text/javascript">

                            myString = '@one@two@three @four';
                            myString = myString.replac e(/^@(.*)$/, '$1');
                            alert(myString) ;

                            </script>

                            Comment

                            Working...