Merge two string

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
wake
Posts: 21
Joined: Thu Jun 25, 2009 6:15 pm

Merge two string

Post by wake » Wed Jul 01, 2009 12:29 am

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!

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Jul 01, 2009 5:53 am

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.
Last edited by Janschenkel on Thu Jul 02, 2009 9:17 pm, edited 1 time in total.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

wake
Posts: 21
Joined: Thu Jun 25, 2009 6:15 pm

Post by wake » Wed Jul 01, 2009 3:51 pm

Janschenkel,

That worked thanks!

!Jerry!
Posts: 16
Joined: Tue Apr 07, 2009 3:49 pm

Post by !Jerry! » Thu Jul 02, 2009 5:51 pm

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

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Thu Jul 02, 2009 9:17 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply