Remove characters from string

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

    #1

    Remove characters from string

    Hello all,

    Would anyone please be able to help?

    I would like to remove all characters after and including the @ from a
    string, for example the string joe.Bloggs@some place.com would become
    Joe Bloggs.

    Thanks You all,

    Jon
  • Martin Honnen

    #2
    Re: Remove characters from string



    Jon wrote:

    [color=blue]
    > I would like to remove all characters after and including the @ from a
    > string, for example the string joe.Bloggs@some place.com would become
    > Joe Bloggs.[/color]

    "joe.Bloggs@som eplace.com".rep lace(/@.*/, '')

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Dietmar Meier

      #3
      Re: Remove characters from string

      Jon wrote:
      [color=blue]
      > I would like to remove all characters after and including the @ from a
      > string,[/color]

      myString = myString.replac e(/@.*/, "");

      Or, compatible with very old script engines

      var atpos = myString.indexO f("@");
      if (atpos > -1) {
      myString = myString.substr ing(0, atpos);
      }
      [color=blue]
      > for example the string joe.Bloggs@some place.com would become
      > Joe Bloggs.[/color]

      Did you mean "joe.Bloggs "?

      ciao, dhgm

      Comment

      • Mick White

        #4
        Re: Remove characters from string

        Jon wrote:
        [color=blue]
        > Hello all,
        >
        > Would anyone please be able to help?
        >
        > I would like to remove all characters after and including the @ from a
        > string, for example the string joe.Bloggs@some place.com would become
        > Joe Bloggs.
        >[/color]

        <script type="text/JavaScript">
        var jb="joe.Bloggs@ someplace.com". split("@")[0].replace(/\./," ")
        jb=jb.charAt(0) .toUpperCase()+ jb.substring(1) ;
        alert(jb);
        </script>

        Mick

        Comment

        • RobB

          #5
          Re: Remove characters from string

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">
          <html>
          <head>
          </head>
          <body>
          <script type="text/javascript">

          function user(addr)
          {
          return addr
          .replace(/^(.+)@.*$/, '$1')
          .replace(/\./g, ' ')
          .replace(/\b./g, function(a){ret urn a.toUpperCase() ;})
          }

          document.write(

          '<pre>' ,
          user('joe.Blow@ someplace.com') ,
          '\n' ,
          user('big.fat.a nnie@mydomain.a u') ,
          '\n' ,
          user('foo.Bar@h aha/vavoom.net') ,
          '</pre>'

          );

          </script>
          </body>
          </html>

          Comment

          • Dr John Stockton

            #6
            Re: Remove characters from string

            JRS: In article <bb17ef27.05042 70744.212baa97@ posting.google. com>,
            dated Wed, 27 Apr 2005 08:44:16, seen in news:comp.lang. javascript, Jon
            <JonMYates@gmai l.com> posted :
            [color=blue]
            >I would like to remove all characters after and including the @ from a
            >string, for example the string joe.Bloggs@some place.com would become
            >Joe Bloggs.[/color]

            S = "joe.Bloggs@som eplace.com"
            S = S.split('@')[0]

            is another way.

            S = "joe.Bloggs@som eplace.com"
            T = S.split('@') // T[0] & T[1] may be useful

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            Working...