Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Split text string to characters, including %%D and unicode items

11 REPLIES 11
Reply
Message 1 of 12
JamesMaeding
2734 Views, 11 Replies

Split text string to characters, including %%D and unicode items

I am making a tool to draw text along plines, and need to split my strings to charcaters.

I know to look for %%D, %%C and several others, but I am wondering if there is a way to detect the difference between the original string charcater count, and the one acad would draw with a given text style.

If the lengths were different, I could check for sequences and handle.

I want to avoid checking every time though, and also detect when some exotic sequence got in that I was not checking for.

 

lisp or .net....


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

11 REPLIES 11
Message 2 of 12
Hallex
in reply to: JamesMaeding

Hi, James

I didn't find .net example here is just C# snip:

 //using System.Text.RegularExpressions;
            //string text = "200%%C";
             string text ="200%%D";      
            string pattern = @"(.*?)%%[D,C]";
            int dia = 0;
            MessageBox.Show(text.Contains("%%D").ToString());
           Regex.Matches(text, pattern).Cast<Match>().All((Match m) =>
           {
               dia = Convert.ToInt32(m.Groups[1].Value);
               return true;
           });
           MessageBox.Show(dia.ToString());

 

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 12
JamesMaeding
in reply to: Hallex

That's slick code, and I will add to my c# library of string extensions.

It approaches things from a standpoint of knowing what to look for though.

 

What if I said "are there any sequences in some string that get converted to one character, or disappear altogether?"

Things like %%U and %%D.

The only way to test that would be some function that looked at the final text value and gave back ascii character values of final string.

%%D seems the same as (chr 176), but I wonder how dependednt this all is on the font.

What if autodesk changes the allowed sequences in strings?

We really need something that gets down to the final characters being displayed. For mtext too...

 

 

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 4 of 12
Hallex
in reply to: JamesMaeding

James, it's too difficult for my dim brain,
I will try to continue tomorrow, though, about fonts,
not every supports characters like in your example, as I remember it
See you later
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 12
JamesMaeding
in reply to: Hallex

dim is as dim does, so GET CRACKING!!!!!

kidding, thx for the help so far 🙂


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 6 of 12
BlackBox_
in reply to: JamesMaeding

FWIW -

 

Here are some additional String extension methods (C#) I came up with while working on this.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 7 of 12
Hallex
in reply to: JamesMaeding

Can you upload text string example for the test?
For mtext too
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 8 of 12
JamesMaeding
in reply to: Hallex

sure:

"try this /U+0178"

 

you see, I have no idea if /U+0178 is a special code that will show as one character, or a typo and it should be /U+0128 or something.

Sequences we think will transform to a character may or may not work in a given environment.

So if my task is to split a string into actual characters that will be drawn, I cannot assume anything.

 

I will check with Kean W on this, seems like this has come up a while back with .net.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 9 of 12
BlackBox_
in reply to: JamesMaeding

In terms of .NET API (I know this thread is still in LISP forum), the TextEditor.Selection.RemoveAllFormatting() Method may be of use here.



"How we think determines what we do, and what we do determines what we get."

Message 10 of 12
JamesMaeding
in reply to: BlackBox_

I think that was what I recalled, but does not pertain to the special character sequences unfortunately.

This might be a tougher question than I thought.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 11 of 12
BlackBox_
in reply to: JamesMaeding


@jmaeding wrote:

I think that was what I recalled, but does not pertain to the special character sequences unfortunately.

This might be a tougher question than I thought.


It may very well be; I only meant that the aforementioned Method could be used to quickly strip the text formatting for Text and MText, and then you need only account for the special characters you previously noted (perhaps I misunderstood your comment to mean you've identified all of them?).

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 12 of 12
Kent1Cooper
in reply to: JamesMaeding


@jmaeding wrote:

I am making a tool to draw text along plines, and need to split my strings to charcaters.

....


Give this a shot -- StringToSeparateCharacters.lsp with is (S2SC) function.  It separates a Text string into strings representing each individual character, including keeping %%D together as a character [as well as %%P & %%C & %%%], likewise %%### special characters and Unicode characters, and retaining under- and/or over-scoring for each character that is within a portion of the original string that has either or both of those.

 

Make a piece of Text including some special characters, Unicode characters, some combination(s) of under- and/or over-scoring, etc.

 

Two additional commands are included, not needed as part of the routine itself, but to show what it does:

 

The S2SCTEST command will ask you to select a piece of Text, and show you the resulting list of the individual characters and special- or Unicode-character strings.

 

The S2SCDEMO command will ask you to select a piece of Text, and place a series of individual-character Text entities below it, something like what you might use to spread along a Polyline [but here in a straight line, and equally spaced ignoring differences in character width], to demonstrate the preservation of special characters, underlining, etc.

 

It doesn't work with internal formatting inside Mtext [see comment near top of file], but it does work with Mtext content if it doesn't have any of that.  And of course it will work with a text string not associated with an existing Text/Mtext entity, such as might be prompted from a User or constructed within a routine.

 

 

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost