@skchui6159 wrote:
(vl-load-com)
(setq links "C:/sdsd/sdff/ppp")
(if (=(vl-string-search "//" links) F)
(vl-string-subst "//" "/" links)
)
(print links)
I want to subst all the "//" to "/". The condition of "if" is satisfactory, why nothing happen? Anyone help?
This return value for this line is an integer, so ensure that variable F is an integer, otherwise the condition will never evaluate to True
(vl-string-search "//" links)
If links variable value is from a path, the line above will always be 2, unless you include a starting position for vl-string-search
Also this line will never move forward, as only the first instance will change when used on your example
(vl-string-subst "//" "/" links)
You should also use vl-string-subst with a start-position argument or jsut simple using while function
Putting them all together
(setq links "C:/sdsd/sdff/ppp")
(while (vl-string-search "/" links)
(setq links (vl-string-subst "\\" "/" links))
)
or via subfunction
(defun backtoforwardslash (links)
(while (vl-string-search "/" links)
(setq links (vl-string-subst "\\" "/" links))
)
links
)
_$ (backtoforwardslash "C:/sdsd/sdff/ppp")
"C:\\sdsd\\sdff\\ppp"
HTH