: FIRSTLETTERS
Input sentence : What you see is what you get.
"WYSIWYG"
(defun ALE_String_ToList (InpStr CarDlm TrueFl / SttPos EndPos TmpLst TmpStr)
(setq
CarDlm (ascii CarDlm) SttPos 0
EndPos (vl-string-position CarDlm InpStr)
)
(while EndPos
(setq
TmpStr (substr InpStr (1+ SttPos) (- EndPos SttPos))
SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
)
(and
(or (/= TmpStr "") TrueFl)
(setq TmpLst (cons TmpStr TmpLst))
)
)
(if (or (/= (setq TmpStr (substr InpStr (1+ SttPos))) "") TrueFl)
(reverse (cons TmpStr TmpLst))
(reverse TmpLst)
)
)
(defun Foo (InpStr / OutStr)
(setq OutStr "")
(foreach ForElm (ALE_String_ToList InpStr " " nil)
(setq OutStr (strcat OutStr (strcase (substr ForElm 1 1))))
)
)
(Foo "What you see is what you get.") => "WYSIWYG"
_$ (acronym " _What you see is what you get.")
"WYSIWYG"
Command: (FLOW " What you $see is !@#$%what you get... .")
"WYSIWYG"
The issue you are encountering is due to the way the function processes spaces and extracts words. Let's modify the function to correctly handle spaces and ensure it generates the full acronym from the phrase:
(defun C:CreateAcronym ( / phrase acronym word startPos endPos)
(setq phrase (getstring T "\nEnter phrase: ")) ; Enable spaces in input
(setq phrase (strcat phrase " ")) ; Append a space to handle the last word
(setq acronym "") ; Initialize acronym as an empty string
(setq startPos 0) ; Initialize starting position for substring
(while (setq endPos (vl-string-search " " phrase startPos)) ; Find next space
(setq word (substr phrase (+ startPos 1) (- endPos startPos))) ; Extract word
(setq acronym (strcat acronym (strcase (substr word 1 1)))) ; Add the first letter to the acronym
(setq startPos (+ endPos 1)) ; Update startPos for next word
)
(prompt (strcat "\nAcronym: " acronym)) ; Display the acronym
(princ)
)
In this revised function, the while loop searches for the next space in the phrase starting from the current startPos. Each word is extracted using substr based on the positions of startPos and endPos, and the first character of each word is added to the acronym. The startPos is then updated to the position after the found space for the next iteration.
Load this updated function into AutoCAD and run it by typing CreateAcronym. It should now correctly generate the full acronym for the input phrase "what you see is what you get" as "WYSIWYG".
Another -Code - Auto/Visual Lisp: [Select]
(defun acronym_ALE (s / l r)
(setq
l (vl-string->list (strcase (vl-string-trim " " s)))
r (list (car l))
)
(while (setq l (cdr l))
(if (= 32 (car l))
(setq r (cons (cadr l) r) l (member 32 l))
)
)
(vl-list->string (reverse r))
)
(setq Astring "@LeeVdh What you see is what you get.")
(acronym_ALE Astring) => "@WYSIWYG"
(acronym_Lee Astring) => "LWYSIWYG"
I don't know if it's a coherent version...Code: [Select](setq Astring "@LeeVdh What you see is what you get.")
(acronym_ALE Astring) => "@WYSIWYG"
(acronym_Lee Astring) => "LWYSIWYG"
Yes but...
I don't know if it's a coherent version...Code: [Select](setq Astring "@LeeVdh What you see is what you get.")
(acronym_ALE Astring) => "@WYSIWYG"
(acronym_Lee Astring) => "LWYSIWYG"
I thought the request was about alphabetic characters...
; for multi spaced strings:
(defun acronym_ALE2 (s / l r)
(setq
l (vl-string->list (strcase (vl-string-trim " " s)))
r (list (car l))
)
(while (setq l (cdr l))
(and
(= 32 (car l)) (/= 32 (cadr l))
(setq r (cons (cadr l) r) l (member 32 l))
)
)
(vl-list->string (reverse r))
)
Yes :) (acronym_ALE2 "What you see is what you get.") => "WYSIWYG"Code - Auto/Visual Lisp: [Select]
_$ (acronym_ALE "What you see is what you get.") "W Y SI WYG"
> acronym "What you see is what you get";;
val it: string = "WYSIWYG"
F#Code - F#: [Select]
let acronym (str: string) = Regex.Matches(str.ToUpper(), @"^[A-Z]|\W[A-Z]")Code: [Select]> acronym "What you see is what you get";;
val it: string = "WYSIWYG"
F#Code - F#: [Select]
let acronym (str: string) = Regex.Matches(str.ToUpper(), @"^[A-Z]|\W[A-Z]")Code: [Select]> acronym "What you see is what you get";;
val it: string = "WYSIWYG"
I considered a similar regex, but abandoned the use of \W as an underscore is considered a word and so bruno's earlier example fails.
> acronym "_What you see is what you get";;
val it: string = "WYSIWYG"
So, here is another method (in lisp).
(defun strparse (aStr delim / strList pos) ... )
; Version 1.20 - 2001 11 08
; Description: convert a string into a list
; Arguments:
; InpStr = string [STR]
; CarDlm = delimiter > 1 or more characters [STR]
;
; Examples:
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz")
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz][(][99" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz" "(" "99")
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz][)][99" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz" ")" "99")
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz][\"][99" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz" "\"" "99")
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz][,][99" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz" "," "99")
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz][.][99" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz" "." "99")
; (ALE_String_ToListStrDlm "\"Abc\"][1.0][1][Xyz][.99" "][")
; => ("\"Abc\"" "1.0" "1" "Xyz" ".99")
; Return Values: [LIST]
;
(defun ALE_String_ToListStrDlm (InpStr StrDlm / SttPos TmpPos DlmLng TmpLst)
(cond
( (/= (type InpStr) (type StrDlm) 'STR) )
( (= InpStr StrDlm) '("") )
( (setq
DlmLng (strlen StrDlm) SttPos 0
TmpPos (vl-string-search StrDlm InpStr SttPos)
)
(while TmpPos
(setq
TmpLst (cons (substr InpStr (1+ SttPos) (- TmpPos SttPos)) TmpLst)
SttPos (+ TmpPos DlmLng)
TmpPos (vl-string-search StrDlm InpStr SttPos)
)
)
(reverse (cons (substr InpStr (1+ SttPos)) TmpLst))
)
)
)