I can't get this code to work
var NickName = "Hello, this is Mike (example) xx "
var NoNickName = "didn't work"
NoNickname = NickName.replace(/ *\([^)]*\) */g, "");
AkelPad.MessageBox(0, NoNickName + " " + NickName, "Remove NickNames", 64 /*MB_ICONINFORMATION*/);
// Result should be
// "Hello, this is Mike"
// Here, we are using regular expression / *\([^)]*\) */g that finds the characters inside brackets (in this case small round brackets) and replace them with empty string.
How to remove text from a string
- Author
- Message
-
Offline
- Posts: 8
- Joined: Sun Nov 13, 2011 7:02 pm
- Location: Dayton, Ohio, USA
-
Offline
- Posts: 1949
- Joined: Sat Mar 06, 2010 7:40 pm
- Location: Poland
Re: How to remove text from a string
These are two different variables.Dellji wrote:...
var NoNickName = "didn't work"
NoNickname = NickName.replace(/ *\([^)]*\) */g, "");
...
-
Offline
- Posts: 8
- Joined: Sun Nov 13, 2011 7:02 pm
- Location: Dayton, Ohio, USA
Re: How to remove text from a string
Your revised code didn't work either.
Also sorry for not giving a clearer example
So here is the proper example:
var NickName = "Hello, this is Michael (Mike) from Ohio"
The result should be
Hello, this is Michael from Ohio
Only the parenthesis “()” and “Mike” should be removed and the two substrings concatenated
The code works in javascript in browser
Also sorry for not giving a clearer example
So here is the proper example:
var NickName = "Hello, this is Michael (Mike) from Ohio"
The result should be
Hello, this is Michael from Ohio
Only the parenthesis “()” and “Mike” should be removed and the two substrings concatenated
The code works in javascript in browser
-
Offline
- Posts: 513
- Joined: Sun Sep 15, 2013 8:25 am
- Location: 013 в Тентуре, семь по Спирали, налево от Большой Медведицы
Re: How to remove text from a string
Dellji wrote: The result should be
Hello, this is Michael from Ohio
Code: Select all
NickName = "Hello, this is Michael (Mike) from Ohio"
NoNickName = NickName.replace(/ *\([^)]*\) */g," ")
WScript.Echo(NoNickName)-
Offline
- Posts: 8
- Joined: Sun Nov 13, 2011 7:02 pm
- Location: Dayton, Ohio, USA
Re: How to remove text from a string
Thanks that workedYuS wrote:Dellji wrote: The result should be
Hello, this is Michael from OhioCode: Select all
NickName = "Hello, this is Michael (Mike) from Ohio" NoNickName = NickName.replace(/ *\([^)]*\) */g," ") WScript.Echo(NoNickName)