Text split

Text split

k005
Advisor Advisor
973 Views
8 Replies
Message 1 of 9

Text split

k005
Advisor
Advisor

Hello everyone !

 

I am printing a text in the form of 25ø8/10 L=250 on a point using "YaziOlustur" method.

How can I separate the L=250 part while printing it?

 

well ;
25ø8/10 a DBText L=250 a DBText

 

25ø8/10 L=250

0 Likes
Accepted solutions (1)
974 Views
8 Replies
Replies (8)
Message 2 of 9

HJohn1
Advocate
Advocate

"Separate while printing" is not clear, well at least to me. What exactly you are after? 

 

I suppose that you are aware of the String.Split method and regular expressions.  Depending on the string variations, you need to decide which approach is better.  For instance, if your strings values always terminate with the same pattern "L=####" after a blank space, simply use the split method on white space.  If you have more variations, I will suggest to use regular expressions.  

0 Likes
Message 3 of 9

k005
Advisor
Advisor
acText.SetDatabaseDefaults();
                acText.Position = pointRes.Value;
                acText.Height = YaziYuks;
                acText.TextString = TextVeri;
                acBlkTblRec.AppendEntity(acText);
                tr.AddNewlyCreatedDBObject(acText, true);
                tr.Commit();

 

 

....

For instance, if your strings values always terminate with the same pattern "L=####" after a blank space, simply use the split method on white space

...

 

this is not a Array. only 1 DBtext object

 

YaziOlustur creates only one Text at the moment. ( 25ø8/10 L=250 )

 

My goal is to create two Texts. on the same axis... (

25ø8/10 L=250)

 

Yes, there is always space. How can I divide from this space?

0 Likes
Message 4 of 9

HJohn1
Advocate
Advocate

I have no idea who YaziOlustur is or how his routine works.  I am simply trying to give you some pointers.  If you need to create more than one DBtext, you need to create a loop after you split the string to add the texts.

 

 string value = "25ø8/10 L=250";
 string[] results = value.Split(" ");

 for (int i = 0; i < results.Length; i++)
    {
      Create the DBtext here
    }
Message 5 of 9

k005
Advisor
Advisor

@HJohn1 

 

In my previous message, I showed how the DBtext related to Create-text is created. =

 

 tr.AddNewlyCreatedDBObject(acText, true); //=  25ø8/10 L=250

 

 

I just want to split. so it can't be split without looping?

 

*******

 

I guess it won't happen... I have to find another solution.

 

Thank you so much.

0 Likes
Message 6 of 9

Jeff_M
Consultant
Consultant
Accepted solution

What is the issue with looping? Something like the following will take your textstring, split in 2, and add 2 DBText objects on the same line. The appears to be exactly what you asked for.

            var TextVeri = "25ø8/10 L=250";
            var strings = TextVeri.Split(' ');
            var width = 0.0;
            foreach (string s in strings)
            {
                var acText = new DBText();                
                acText.SetDatabaseDefaults();
                acText.Position = new Point3d(pointRes.Value.X + width, pointRes.Value.Y, pointRes.Value.Z);
                acText.Height = 2; //I don't know what the YaziOlustur method is 
                acText.TextString = s;
                acBlkTblRec.AppendEntity(acText);
                tr.AddNewlyCreatedDBObject(acText, true);
                width = acText.GeometricExtents.MaxPoint.X + 2; //determine amount to offset the second text in X direction
            }
            tr.Commit();
Jeff_M, also a frequent Swamper
EESignature
Message 7 of 9

k005
Advisor
Advisor

 

...

determine amount to offset the second text in X direction

...

 

Thank you so much.

 

Yes that way... only the second post has a lot of spacing... I think I can figure it out myself.

 

25ø8/10 L=250

 

The length of the spaces should be as long as the text.

0 Likes
Message 8 of 9

Jeff_M
Consultant
Consultant

the 2 in my width calculation is 2 drawing units. Just make that distance smaller to decrease the spacing.

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 9

k005
Advisor
Advisor

Yes. I was able to solve that part. Thank you so much. 🤗

0 Likes