2017-10-31 1 views
-3

CStringdider 텍스트 상자에서 긴 sb 문자열을 사용하는 stringbuilder (sb)가 있습니다.하위 문자열이 x보다 큰 경우 StringBuilder에서 하위 문자열을 바꾸는 방법은 무엇입니까?

내 문제는 CSS! important 태그가 CKEditor 내에서 생성되는 테이블에서 작동하지 않는다는 것입니다.

테이블을 만들 때 최대 너비를 설정하고 테이블 너비 값이 일정량을 초과하는 경우에만 테이블 너비 값을 편집하려고합니다. IE 폭 : 200 픽셀 값을 모두 StringBuilder 예에 삽입하기 전에 : 900px 그래서 폭으로 값을 대체 200 픽셀을 초과

<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> 

나 또한 몇 가지 정규식 접근 방식을 시도했지만 한 나는 내가 잘 알고 아니라서 Regex를 사용하지 않을 것입니다.

답변

0

s.some_long_string은 위 질문의 html 문자열입니다. 문자의 수 및/또는 순서를 가지고 다음 "픽셀"로 끝나는 : "폭"

string TempString = s.some_long_string;  
string replace; 

이것은로 시작하는 문자열의 일부를 찾습니다.

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

"폭 :"이 나타나는 모든 인스턴스를 수집합니다. 이는 문자열의 나머지 부분에서 숫자를 분리

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; 
    } 
} 
관련 문제