<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re : VB.NET Update Mtext content with formating in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886409#M32728</link>
    <description>&lt;P&gt;Here's a Regex way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;mtext.Contents = Regex.Replace(mtext.Contents, @"(?i)(?&amp;lt;!\\)P", "Q");&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Feb 2017 18:09:59 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2017-02-17T18:09:59Z</dc:date>
    <item>
      <title>VB.NET Update Mtext content with formating</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886066#M32726</link>
      <description>&lt;P&gt;I have a VB.NET routine to find and replace text strings. I am snagging on formatted MTEXT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case "AcDbMText"&lt;BR /&gt;Dim NewTextString As String = ""&lt;BR /&gt;Dim mtextObj As MText = trans.GetObject(selObj.ObjectId, OpenMode.ForWrite, False, True)&lt;BR /&gt;Dim OldTextString As String = mtextObj.Contents&lt;BR /&gt;NewTextString = Replace(OldTextString, CurrentFind, CurrentReplace, 1, -1, CompareMethod.Text)&lt;BR /&gt;If OldTextString &amp;lt;&amp;gt; NewTextString Then&lt;BR /&gt;mtextObj.Contents = NewTextString&lt;BR /&gt;End If&lt;BR /&gt;mtextObj.Dispose()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now the routine works a little too well, it replaces in formatting as well as the string. For instance if I replace "p" with "q" it takes out all the paragraph formatting under "\P".&amp;nbsp;Is there a way to distinguish between actual visible and formatting. I was going to make an exceptions list but that would get rather lengthy and sticky especially when it comes to text styles.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 15:49:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886066#M32726</guid>
      <dc:creator>Jedimaster</dc:creator>
      <dc:date>2017-02-17T15:49:06Z</dc:date>
    </item>
    <item>
      <title>Re : VB.NET Update Mtext content with formating</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886341#M32727</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Concerning the "\P" issue, you can simply replace back the newly created "\Q" with "\P":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;mtext.Contents = mtext.Contents.Replace("P", "Q").Replace("\\Q", "\\P");&lt;/PRE&gt;
&lt;P&gt;You can also use the unformated text returned by the MText.Text property tou build a replacing dictionary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                var text = mtext.Text;
                var dict = new Dictionary&amp;lt;string, string&amp;gt;();
                foreach (var str in text.Split(' ', '\n', '\r'))
                {
                    if (str.Contains("P") &amp;amp;&amp;amp; !dict.ContainsKey(str))
                        dict.Add(str, str.Replace('P', 'Q'));
                }

                var contents = mtext.Contents;
                foreach (var pair in dict)
                {
                    contents = contents.Replace(pair.Key, pair.Value);
                }

                mtext.Contents = contents;&lt;/PRE&gt;
&lt;P&gt;You can also use regular expressions but I have no time right now to write an example.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:34:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886341#M32727</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-02-17T17:34:27Z</dc:date>
    </item>
    <item>
      <title>Re : VB.NET Update Mtext content with formating</title>
      <link>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886409#M32728</link>
      <description>&lt;P&gt;Here's a Regex way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;mtext.Contents = Regex.Replace(mtext.Contents, @"(?i)(?&amp;lt;!\\)P", "Q");&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 18:09:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/vb-net-update-mtext-content-with-formating/m-p/6886409#M32728</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-02-17T18:09:59Z</dc:date>
    </item>
  </channel>
</rss>

