Thứ Bảy, 25 tháng 5, 2024

Chuyển đổi Text tiếng Trung Nhật Hàn | Convert text string from Japanese Korean Chinese | AutoCAD dotNet

Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản

    
Thông tin thêm: 👉👉👉
Bảng mã ký tự latin trong font chữ tiếng Trung, Hàn, Nhật



1 Thêm MyCommands.cs

(Copy nội dung sau)
Code:
    internal class MyCommands
    {
        [CommandMethod("CloneEntity")]
        public void cmdd_CloneEntity()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            if (doc == null) return;

            Editor ed = doc.Editor;

            var sf = new SelectionFilter(new TypedValue[] { new TypedValue(0, "*TEXT") });
            var psr = ed.GetSelection(sf);
            if (psr.Status != PromptStatus.OK) return;

            var id0 = psr.Value.GetObjectIds().FirstOrDefault();

            var txt0 = id0.Clone<Entity>();
            if (txt0.Bounds.HasValue)
            {
                var text = txt0.GetText().Normalize(NormalizationForm.FormKC);
ed.WriteMessage("\n" + text); } } }


2 Thêm Extensions.cs

(Copy nội dung sau)
Code:
    public static string GetText(this Entity ent)
        {
            string str = null;
            if (str == null)
            {
                AttributeReference attr = ent as AttributeReference;
                if (attr != null) return attr.TextString;
                AttributeDefinition att = ent as AttributeDefinition;
                if (att != null) return att.Tag;
                MText mtxt = ent as MText;
                if (mtxt != null) return mtxt.Text;
                DBText txt = ent as DBText;
                if (txt != null) return txt.TextString;
            }
            return "";
        }

        public static T Clone<T>(this ObjectId id) where T : Entity
        {
            T d = null;
            using (Transaction tr = id.Database.TransactionManager.StartTransaction())
            {
                DBObject db = tr.GetObject(id, OpenMode.ForRead);
                d = db.Clone() as T;
                tr.Commit();
            }
            return d;
        }


3 Sử dụng

(Copy nội dung sau)
Code:
U+FF0x		!	"	#	$	%	&	'	(	)	*	+	,	-	.	/
U+FF1x	0	1	2	3	4	5	6	7	8	9	:	;	<	=	>	?
U+FF2x	@	A	B	C	D	E	F	G	H	I	J	K	L	M	N	O
U+FF3x	P	Q	R	S	T	U	V	W	X	Y	Z	[	\	]	^	_
U+FF4x	`	a	b	c	d	e	f	g	h	i	j	k	l	m	n	o
U+FF5x	p	q	r	s	t	u	v	w	x	y	z	{	|	}	~	⦅

string userInput = "Stackoverflow";
string result = userInput.Normalize(NormalizationForm.FormKC);


---------------------------------------------------------------------------------------------
Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản - Tác giả ứng dụng in D2P

    

Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!

Không có nhận xét nào:

Đăng nhận xét

Quy hoạch Giao thông | Quy hoạch LDT 3D năm 2025

Ứng dụng được phát triển bởi đội ngũ AutoLISP Thật là đơn giản       Thông tin thêm: 👉👉👉