Page 1 of 1

Merge two string

Posted: Wed Jul 01, 2009 12:29 am
by wake
Can someone point me in the right direction for merging 2 separate strings?

Say I have the following strings:
C:\Users\myuser\department\file.txt
Z:\shared\

And I want to get the following:
Z:\shared\department\file.txt

Essentially I want to find "department" in the first string and append everything from the start of that point to the second string.

Hopefully this makes sense. In vb.net I would just run an InStr() function to return an integer where department starts. Then I could use the Mid() function to extract that exact portion of the string.

Thanks in advance!

Posted: Wed Jul 01, 2009 5:53 am
by Janschenkel
Use the offset function as equivalent for 'InStr' and a char chunk expression as equivalent for 'Mid'

Code: Select all

put "C:\Users\myuser\department\file.txt" into tLocalPath
put "Z:\shared\" into tRemoteDir
put offset("department", tLocalPath) into tOffset
put char tOffset to -1 of tLocalPath into tRelativePath
put tRemoteDir & tRelativePath into tRemotePath
(edited to fix typo as spotted by Jerry)

Jan Schenkel.

Posted: Wed Jul 01, 2009 3:51 pm
by wake
Janschenkel,

That worked thanks!

Posted: Thu Jul 02, 2009 5:51 pm
by !Jerry!
Hi Jan!

A small typo stealed in the last line of your example - "tRelativePath" in place of "tPartialPath".

I'm not a hair-splitter, I'm newbie in rev and I'm reading your "lessons" very carefully because you have a great ability to show things simply :D

Jerry

Posted: Thu Jul 02, 2009 9:17 pm
by Janschenkel
Ah, heh, oops... This happens often, as I change my mind about the name of a variable right in the middle of scripting ;-)
Glad to hear you find my posts helpful! I'm sure you'll do the same for others here when you get a chance.

Jan Schenkel.