Forum Moderators: open

Message Too Old, No Replies

Remove text from other text

         

chrisjoha

8:50 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



var str1 = 'text';
var str2 = 'some text in here';

Is there an easy way to create str3 which is str2 except for the contents of str1? IE:

var str3 = some_neat_function(str1, str2);

Output:
'some in here'.

I need something like this to dynamically add and remove class names from elements on given events (such as onmouseover and onmouseout in tables to highlight complete rows/columns)

Rambo Tribble

1:09 pm on Aug 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably the easiest way to address this simple case is with split(). Something like:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var str1 = 'text ';
var str2 = 'some text in here';
var sub_strs=str2.split(str1);
alert(sub_strs[0]+sub_strs[1]);
</script>
</head>
<body>
</body>
</html>