Counting line feeds and remove unwanted string content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Greetings,
I have a question related to counting the number of line feed in a string contained in the Text / MText / MLeader and defining function based on these data.
As far as I know, a line feed in AutoLISP can be denoted by two characters:
"\n" (is equivalent to 10 ASCII character)
or
"\\P" - for strings contained in the Text / MText / MLeader (is equivalent to 92 and 80 ASCII characters following each other)
Thus, the number of line feed can be calculated by counting the number of characters "\n" and "\\P" contained in the string.
Now I need a function that, based on counted line feeds, would return a certain result:
• if the string does not contain line feed characters then return nil:
"Apple" >>> nil
• if the string contains one line feed, that is, a line break in a string into two lines (the top line may be empty) then return this string:
"Apple\\PBanana" >>> "Apple\\PBanana"
"\nApple" >>> "\nApple"
• if there is more than one line feed in the string then it is required to keep the top two lines in string and delete the other content of the string, then return the transformed string.
"Apple\\PBanana\nOrange" >>> "Apple\\PBanana"
"\nApple\\PBanana\nOrange" >>> "\nApple"
Any help would be greatly appreciated.
Thank you in advance.