469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Remove characters from string

Jon
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 jo********@someplace.com would become
Joe Bloggs.

Thanks You all,

Jon
Jul 23 '05 #1
5 91749


Jon wrote:

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


"jo********@someplace.com".replace(/@.*/, '')

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
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 jo********@someplace.com would become
Joe Bloggs.


Did you mean "joe.Bloggs"?

ciao, dhgm
Jul 23 '05 #3
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 jo********@someplace.com would become
Joe Bloggs.


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

Mick
Jul 23 '05 #4
<!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('j*******@someplace.com') ,
'\n' ,
user('b************@mydomain.au') ,
'\n' ,
user('foo.Bar@haha/vavoom.net') ,
'</pre>'

);

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

Jul 23 '05 #5
JRS: In article <bb**************************@posting.google.com >,
dated Wed, 27 Apr 2005 08:44:16, seen in news:comp.lang.javascript, Jon
<Jo*******@gmail.com> posted :
I would like to remove all characters after and including the @ from a
string, for example the string jo********@someplace.com would become
Joe Bloggs.


S = "jo********@someplace.com"
S = S.split('@')[0]

is another way.

S = "jo********@someplace.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.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.
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Joseph | last post: by
15 posts views Thread by morleyc | last post: by
9 posts views Thread by Smiley | last post: by
2 posts views Thread by Konstantinos Pachopoulos | last post: by
10 posts views Thread by Mike Copeland | last post: by
26 posts views Thread by Brad | last post: by
4 posts views Thread by MC | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.