vl-string-right-trim

jclaidler

Usenet Archive
Joined
Apr 30, 2003
Messages
185
Reaction score
0
Is there a way to trim a desired number of characters and/or spaces ?? For example, remove abcd from 1234abcd.
 
No but you can determine the starting position of the string you wish to remove using vl-string-position then retrieve the portion of the string from position one to position N - 1.
 
; CarDlm = character to subst or remove
; NewDlm = new string for subst or "" for remove
; StgVal = original string

(defun ALE_StringSubst (CarDlm NewDlm StgVal / AscDel)
(setq AscDel (ascii CarDlm))
(while (vl-string-position AscDel StgVal)
(setq StgVal (vl-string-subst NewDlm CarDlm StgVal))
)
StgVal
)

; Original : "abcd1234abcd1234abcd"
; To remove: "abcd"

(ALE_StringSubst
"@" ""
(vl-string-translate "abcd" "@@@@" "abcd1234abcd1234abcd")
)

; Result: "12341234"
 
The title of your message say it all !!!

(vl-string-right-trim "abcd" "1234abcd")

jclaidler a écrit :
 
or better:

;
; Multiple substitution of a pattern string - 05/21/03
; Original by John Uhden, added SttPos argument
;
; Arguments:
; NewStr: the string to be substituted for pattern
; PatStr: a string containing the pattern to be replaced ; InpStr: the string to be searched for pattern ; SttPos: 0, nil or an integer identifying the starting position of the search ; ; Return Values: the value of string after any substitutions have been made ; ; Example:
; (ALE_StringSubstAll "new" "old" "old test for old method" nil) ; ; Notes:
; the search is case-sensitive
; SttPos = 0 or nil > substitution start from first character ; NewStr = "" remove all instances of PatStr from SttPos ; ; Suggestions:
; use (vl-string-translate "\t" " " "Hi\tthis\tis\ta\ttest!") ; for single (or set) character substitution (not to remove) ; (N.B. the inversion of arguments) ; (defun ALE_StringSubstAll (NewStr PatStr InpStr SttPos / NewLen) (setq NewLen (strlen NewStr)) (while (setq SttPos (vl-string-search PatStr InpStr SttPos)) (setq InpStr (vl-string-subst NewStr PatStr InpStr SttPos) SttPos (+ SttPos NewLen) ) ) InpStr )
 
So you know what the first 12 caracters are ok..then

(setq Bname "720-1264-002-02223a")
(setq FirstPartPart (substr Bname 1 12))
(setq LastPart (substr Bname 13))

jclaidler a écrit :
 
nope... the constant will be "-##### then letter" or nothing at the end of the block.
 
With all the suggestions.....you should have the solution...or explain the problem clearly.

jclaidler a écrit :
 

Latest threads

Back
Top