467,923 Members | 1,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

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

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
  • viewed: 2361
Share:
4 Replies
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
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
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
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.

Similar topics

1 post views Thread by timothy ma and constance lee | last post: by
15 posts views Thread by Patrick Olurotimi Ige | last post: by
10 posts views Thread by pamelafluente | last post: by
7 posts views Thread by f pemberton | last post: by
3 posts views Thread by Hvid Hat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.