PDA

View Full Version : String Manipulation



Mike.Perry
2004-10-13, 10:48 AM
Hi

Need a little help here please, the following are just examples -

(setq DwgPath1 (getvar "DwgPreFix"))

"C:\\AutoCAD\\Support\\Lib\\Details\\Concrete"

(setq DwgPath2 (getvar "DwgPreFix"))

"C:\\Support\\Lib\\StandardDetails"

(setq DwgPath3 (getvar "DwgPreFix"))

"X:\\AutoCAD2005\\Lib\\Manufacture\\SteelWorkDetails" <- There shouldn't be a space between ls (can't get formatting to remove it)



I need to delete / remove everything left of "Lib" ie

DwgPath1 -> "Lib\\Details\\Concrete"

DwgPath2 -> "Lib\\StandardDetails"

DwgPath3 -> "Lib\\Manufacture\\SteelWorkDetails"



I can then use vl-string-translate to replace \\ with / ie

DwgPath1 -> (vl-string-translate "\\" "/" "Lib\\Details\\Concrete")

"Lib/Details/Concrete"

DwgPath2 -> (vl-string-translate "\\" "/" "Lib\\StandardDetails")

"Lib/StandardDetails"

DwgPath3 -> (vl-string-translate "\\" "/" "Lib\\Manufacture\\SteelWorkDetails")

"Lib/Manufacture/SteelWorkDetails"

Thanks, Mike

stig.madsen
2004-10-13, 11:56 AM
Hey Mike,
Is that your kid with the cheek color of W.C. Fields? :)

Here's an attempt of a function that will cut a path down to a specified folder. You could perhaps use it like this:

(setq myPath "C:\\AutoCAD\\Support\\Lib\\Details\\Concrete"
myFolder "Lib")

(if (setq removePath (filenameTrim myPath myFolder))
(vl-string-subst myFolder removePath myPath))

-> "Lib\\Details\\Concrete"


(defun filenameTrim (fname toString / flen)
(while (and (/= (strlen fname) flen)
(/= (substr fname
(1+ (- (strlen fname) (strlen toString)))
(strlen toString)
)
toString
)
)
(setq flen (strlen fname)
fname (vl-filename-directory fname)
)
)
(if (/= flen (strlen fname))
fname
)
)

Mike.Perry
2004-10-13, 12:38 PM
Hey Mike,
Is that your kid with the cheek color of W.C. Fields? :)Hi Stig

I wish, it's my niece at her first swimming lesson last Sunday.

Thanks for the code, as always it's works like a charm :)

:beer: Mike