2017-10-31 2 views
-3

私はsbです。文字列ビルダー(sb)を持っています。長い文字列のHTMLを(CKEditorテキストボックスから)追加しています。部分文字列がxより大きい場合、StringBuilder内の部分文字列を置き換える方法は?

私の問題は、CSS!重要なタグがCKEditor内で作成されているテーブルでは機能していないことです。

テーブルの最大幅(作成されている場合)を設定し、テーブル幅の値が一定量を超えた場合にのみ編集しようとしています。 IE幅:StringBuilderの 例に挿入する前に、200pxの値:

<style> 
.div table{width:200px; !Important} 
</style> 

<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 
    elit, sed do eiusmod 
    tempor incididunt ut labore et dolore magna aliqua."</p> 

    <p>de Finibus Bonorum et Malorum", written by Cicero in 45 BC</p> 

     <p>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem 
      accusantium doloremque laudantium, totam"</p> 

     <p> </p> 

     <table border="1" cellpadding="1" cellspacing="1" style="height:55px; width:900px"> 
      <tbody> 
       <tr> 
        <td> </td> 
        <td>Value</td> 
       </tr> 
       <tr> 
        <td>Example</td> 
        <td>50</td> 
       </tr> 
      </tbody> 
     </table> 

     <p> </p> 

     <p>1914 translation by H. Rackham</p> 

     <p>"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system."</p> 

私は私はいくつかの正規表現のアプローチをも試みたが、私はそれに非常に精通していないよので、900pxはとても幅の値を置き換える200pxのを超えてRegexを使用しないでください。

答えて

0

s.some_long_stringは上記質問からのhtmlの文字列でした。 、任意の数の文字および/または配列を有し、その後、「PX」で終わる:「幅」

string TempString = s.some_long_string;  
string replace; 

これはで始まる文字列の一部を検索します。

MatchCollection matchlist = Regex.Matches(s.some_long_string, "width:(.*)px"); 

"width:"がポップアップするすべてのインスタンスを収集します。これは、文字列の残りの部分から数を分離

var list = matchlist.Cast<Match>().Select(match => match.Value).ToList(); 

foreach (var v in list) 
{ 
    replace = v; 

var resultString = Regex.Match(v, @"\d+").Value; 

    if (Convert.ToInt32(resultString) > 745) 
    { 
     TempString = TempString.Replace(replace, "width:745px"); 
     s.some_long_string = TempString; 
    } 
} 
関連する問題