473,390 Members | 1,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 91910


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
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.