To replace characters, I currently run the following code:
oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with tab(s)
Ideally, I'd like to replace the hard coded string \xFC with a variable such
as delim.
I tried:
oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with tab(s)
but that does not appear to work.
Is this possible? If so, how would I go about coding?
Thanks and regards, Ian Renfrew 4 1667
Ian Renfrew wrote: To replace characters, I currently run the following code:
oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with
tab(s) Ideally, I'd like to replace the hard coded string \xFC with a
variable such as delim.
I tried:
oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with
tab(s) but that does not appear to work.
Is this possible? If so, how would I go about coding?
Thanks and regards, Ian Renfrew
Use the RegExp constructor to compile the regex at run-time:
var re = new RegExp(delim, 'g');
oStr = oStr.replace(re, '\t'); http://www.webreference.com/js/column5/define.html
You'll need to use the regular expression constructor not regular
expression literals in your str.replace() function. The RegExp
constructor is passed a string that represents the regular expression
pattern, so you can make that string by concatenating some variable.
"Ian Renfrew" <ia*********@sympatico.ca> wrote in
news:Fn*******************@news20.bellglobal.com: To replace characters, I currently run the following code:
oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with tab(s)
Ideally, I'd like to replace the hard coded string \xFC with a variable such as delim.
I tried:
oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with tab(s)
but that does not appear to work.
Is this possible? If so, how would I go about coding?
Thanks and regards, Ian Renfrew
either,
delim=new RegExp("\\xFC", "g");
or
delim = /\xFC/g
then
oStr=oStr.replace(delim, "\t");
Thats done the trick. Learn something new each day. Thanks Rob, Mark and
John for your assistance.
.... Ian
"Ian Renfrew" <ia*********@sympatico.ca> wrote in message
news:Fn*******************@news20.bellglobal.com.. . To replace characters, I currently run the following code:
oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with tab(s)
Ideally, I'd like to replace the hard coded string \xFC with a variable such as delim.
I tried:
oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with tab(s)
but that does not appear to work.
Is this possible? If so, how would I go about coding?
Thanks and regards, Ian Renfrew
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: McKirahan |
last post by:
How would I use a regular expression to remove all trailing Carriage Returns
and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance.
Also, are they any great references for learning...
|
by: Jon Maz |
last post by:
Hi All,
I want to strip the accents off characters in a string so that, for example,
the (Spanish) word "práctico" comes out as "practico" - but ignoring case,
so that "PRÁCTICO" comes out as...
|
by: Jon Maz |
last post by:
Hi All,
I want to strip the accents off characters in a string so that, for example,
the (Spanish) word "práctico" comes out as "practico" - but ignoring case,
so that "PRÁCTICO" comes out as...
|
by: Csaba Gabor |
last post by:
I need to come up with a function
function regExpPos (text, re, parenNum) { ... }
that will return the position within text of RegExp.$parenNum if there
is a match, and -1 otherwise.
For...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
| |