473,505 Members | 15,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 91914


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4168
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
11
18242
by: deko | last post by:
I need to loop through a string and remove all characters except numbers or letters. I am getting an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the...
8
8486
by: Paul | last post by:
Hi, My VB is very rusty I'm afraid! What would be the most efficient way to remove the following ASCII characters from a string? à è ì ò ù À È Ì Ò Ù á é í ó ú ý Á É Í Ó Ú Ý â ê î ô û Â Ê Î Ô...
15
50135
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
9
3982
by: Smiley | last post by:
Hi, Can someone tell me how to remove aspostophe (') from user input. I don't want to give any error message. Just want to remove or change it to "" or null, such input when it appear anywhere...
11
14845
by: cody | last post by:
Is there a method to replace special characters like Ä (A-Umlaut) with A, Ö (O-Umlaut) with O, and so on? Sure, I could look for each character separately and replace it with its...
2
6568
by: Konstantinos Pachopoulos | last post by:
Hi, i have the following string s and the following code, which doesn't successfully remove the "\", but sucessfully removes the "\\". .... if i!="\\": .... newS=newS+i .......
10
3169
by: Mike Copeland | last post by:
I have data I need to normalize - it's "name" data. For example, I have the following: "Watts, J.C." I wish to (1) parse the "first name" ("J.C.") and adjust it to "JC". Essentially, I want to...
26
13761
by: Brad | last post by:
I'm writing a function to remove certain characters from strings. For example, I often get strings with commas... they look like this: "12,384" I'd like to take that string, remove the comma...
4
9886
by: MC | last post by:
Is there a string function in .NET that will remove the accent marks from letters? I know that's a slightly vague request... and that I could implement it by table lookup (and will do so unless...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.