Adding some strings recursively

A

ASM

Me a écrit :
how can you add a string aaaaaa at the beginning of a given string
"string" and bbbbb at the end of it especially recursively ifthere are
multiple "string"'s in a given text file ?

the content of givent text file must be a string too

file myFile.txt :
myText = 'here is some words to tell you nothing';

html file :
<html>
<script type="text/javascript" src="myFile.txt"></script>
<script type="text/javascript">
str1 = 'aaaa';
str2 = 'bbbb';
str3 = 'cccc';

function preAdd(original, added) {
return added + original;
}

function postAdd(original, added) {
return original + added;
}
</script>

<p><a href="javascript:alert(preAdd(str1, str2))">Add str2 before str1</a>
<p><a href="javascript:alert(postAdd(str1, str2))">Add str2 after str1</a>
<p><a href="javascript:alert(preAdd(postAdd(str1, str2), str3))">
Add str2 after str1 and str3 before
</a>
<p>
<a href="javascript:alert(
preAdd(postAdd(myText,' at all'),'Hello ! ')
)">
Add "at all" after "my text" and "Hello !" before
</a>
</html>
 
A

ASM

Randy Webb a écrit :
Or, wait a couple of hours and someone else here will write your code
for you

Lost !

it happened almost 10 hours earlier ... :)


(or 12 if you count the 2 for waiting)
 
R

Randy Webb

Me said the following on 10/27/2006 7:36 AM:
how can you add a string aaaaaa at the beginning of a given string
"string" and bbbbb at the end of it especially recursively ifthere are
multiple "string"'s in a given text file ?

You simply replace the "string" with a new string "aaaaaa string bbbbb".
Look into the .replace() method and Regular Expressions

Another alternative is to split() your string on your first string, then
put the array back together using join() using the replace string as the
joiner.

Write your best effort and post it to get help debugging it.

Or, wait a couple of hours and someone else here will write your code
for you - I won't.
 
R

Randy Webb

ASM said the following on 10/26/2006 4:57 PM:
Randy Webb a écrit :

Lost !

it happened almost 10 hours earlier ... :)


(or 12 if you count the 2 for waiting)

I have always said that if you can disguise your homework assignment
well enough, then someone in comp.lang.javascript will write it for you.
Even if it isn't homework, you can get just about any code you want
written here if you find a person willing to do it for free :)
 
M

Me

how can you add a string aaaaaa at the beginning of a given string
"string" and bbbbb at the end of it especially recursively ifthere are
multiple "string"'s in a given text file ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top