Remove characters from string

Discussion in 'Javascript' started by Jon, Apr 27, 2005.

  1. Jon

    Jon Guest

    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 would become
    Joe Bloggs.

    Thanks You all,

    Jon
    Jon, Apr 27, 2005
    #1
    1. Advertising

  2. Jon wrote:


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


    "".replace(/@.*/, '')

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 27, 2005
    #2
    1. Advertising

  3. Jon wrote:

    > I would like to remove all characters after and including the @ from a
    > string,


    myString = myString.replace(/@.*/, "");

    Or, compatible with very old script engines

    var atpos = myString.indexOf("@");
    if (atpos > -1) {
    myString = myString.substring(0, atpos);
    }

    > for example the string would become
    > Joe Bloggs.


    Did you mean "joe.Bloggs"?

    ciao, dhgm
    Dietmar Meier, Apr 27, 2005
    #3
  4. Jon

    Mick White Guest

    Jon wrote:

    > 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 would become
    > Joe Bloggs.
    >


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

    Mick
    Mick White, Apr 27, 2005
    #4
  5. Jon

    RobB Guest

    <!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){return a.toUpperCase();})
    }

    document.write(

    '<pre>' ,
    user('') ,
    '\n' ,
    user('') ,
    '\n' ,
    user('foo.Bar@haha/vavoom.net') ,
    '</pre>'

    );

    </script>
    </body>
    </html>
    RobB, Apr 27, 2005
    #5
  6. JRS: In article <>,
    dated Wed, 27 Apr 2005 08:44:16, seen in news:comp.lang.javascript, Jon
    <> posted :

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


    S = ""
    S = S.split('@')[0]

    is another way.

    S = ""
    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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Apr 28, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pascal
    Replies:
    3
    Views:
    668
    Roel Mathys
    Dec 4, 2003
  2. Pascal
    Replies:
    0
    Views:
    279
    Pascal
    Dec 3, 2003
  3. Replies:
    4
    Views:
    475
    Stan Milam
    Apr 30, 2005
  4. rvino
    Replies:
    0
    Views:
    4,637
    rvino
    Aug 14, 2007
  5. Brad
    Replies:
    19
    Views:
    710
    Jerry Coffin
    May 26, 2008
Loading...

Share This Page