Remove characters from string

J

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 (e-mail address removed) would become
Joe Bloggs.

Thanks You all,

Jon
 
M

Martin Honnen

Jon wrote:

I would like to remove all characters after and including the @ from a
string, for example the string (e-mail address removed) would become
Joe Bloggs.

"(e-mail address removed)".replace(/@.*/, '')
 
D

Dietmar Meier

Jon said:
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 (e-mail address removed) would become
Joe Bloggs.

Did you mean "joe.Bloggs"?

ciao, dhgm
 
M

Mick White

Jon said:
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 (e-mail address removed) would become
Joe Bloggs.

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

Mick
 
R

RobB

<!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('(e-mail address removed)') ,
'\n' ,
user('(e-mail address removed)') ,
'\n' ,
user('foo.Bar@haha/vavoom.net') ,
'</pre>'

);

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

Dr John Stockton

JRS: In article <[email protected]>,
dated Wed, 27 Apr 2005 08:44:16, seen in Jon
I would like to remove all characters after and including the @ from a
string, for example the string (e-mail address removed) would become
Joe Bloggs.

S = "(e-mail address removed)"
S = S.split('@')[0]

is another way.

S = "(e-mail address removed)"
T = S.split('@') // T[0] & T[1] may be useful
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top