By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,874 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,874 IT Pros & Developers. It's quick & easy.

A simple 'Replace' and 'Substring' question: How to add a string to another string

P: n/a
SM
Hello,
I have a simple question, but can't find the answer.
I have a string that contains a path to a file
I want to add another string to the end of that string

So, if i have :
path = document/disco/album/hello.doc

i want it to become :
document/disco/album/hello_large.xls

it doesnt necessary means that the file will always end with .doc it
could be also .doc, xls... so i dont want to hardcode that part.

I've try using replace and substring with no success

Can someone help me with such a simple function?

Thanks
Marco

Apr 25 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Lee
SM said:
>
Hello,
I have a simple question, but can't find the answer.
I have a string that contains a path to a file
I want to add another string to the end of that string

So, if i have :
path = document/disco/album/hello.doc

i want it to become :
document/disco/album/hello_large.xls

it doesnt necessary means that the file will always end with .doc it
could be also .doc, xls... so i dont want to hardcode that part.

I've try using replace and substring with no success

Can someone help me with such a simple function?
The first step is to define precisely what you want.
You don't want to add another string to the end of a string.
It sounds like you're asking how to replace the last "dot" and
whatever follows it with "_large.xls". Is that right, or could
the replacement text be variable?
--

Apr 25 '07 #2

P: n/a
SM
On Apr 25, 1:01 pm, Lee <REM0VElbspamt...@cox.netwrote:
SM said:


Hello,
I have a simple question, but can't find the answer.
I have a string that contains a path to a file
I want to add another string to the end of that string
So, if i have :
path = document/disco/album/hello.doc
i want it to become :
document/disco/album/hello_large.xls
it doesnt necessary means that the file will always end with .doc it
could be also .doc, xls... so i dont want to hardcode that part.
I've try using replace and substring with no success
Can someone help me with such a simple function?

The first step is to define precisely what you want.
You don't want to add another string to the end of a string.
It sounds like you're asking how to replace the last "dot" and
whatever follows it with "_large.xls". Is that right, or could
the replacement text be variable?

--
Hey Lee,
Sorry for not being so clear.
The replacement text is always the text '_large', and the replacement
always happens before the extension of the file (that is before the
first 'dot'). But i do want to keep the extension.

ie
images/disco/alive.jpg ---images/disco/alive_large.jpg

images/disco/alive.jpg ---images/disco/alive_large.jpg

Hope this helps

Thanks again
Marco

Apr 27 '07 #3

P: n/a
On Apr 26, 6:58 pm, SM <servandomont...@gmail.comwrote:
The replacement text is always the text '_large', and the replacement
always happens before the extension of the file (that is before the
first 'dot'). But i do want to keep the extension.

ie
images/disco/alive.jpg ---images/disco/alive_large.jpg

images/disco/alive.jpg ---images/disco/alive_large.jpg
var newText=textVar.replace(/(.+)(\..+)/,'$1_large$2')

OR

var lastIx=textVar.lastIndexOf('.')
var newText=textVar.slice(0,lastIx)+'_large'+textVar.s lice(lastIx)

Apr 27 '07 #4

P: n/a
SM
On Apr 27, 1:50 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On Apr 26, 6:58 pm, SM <servandomont...@gmail.comwrote:
The replacement text is always the text '_large', and the replacement
always happens before the extension of the file (that is before the
first 'dot'). But i do want to keep the extension.
ie
images/disco/alive.jpg ---images/disco/alive_large.jpg
images/disco/alive.jpg ---images/disco/alive_large.jpg

var newText=textVar.replace(/(.+)(\..+)/,'$1_large$2')

OR

var lastIx=textVar.lastIndexOf('.')
var newText=textVar.slice(0,lastIx)+'_large'+textVar.s lice(lastIx)
thank you

Marco

Apr 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.