2012-06-21 344 views
4

我有一個字符串,在SQL中我測試過這個字符串包含不可打印的字符,但我找不到那些。打印給定字符串中的非打印字符?

所以任何人都可以建議我如何通過傳遞該字符串來找到並打印C#中的那些非打印字符 ?

我在8月訂了一個金牛座,它還沒有預定,我是 只是想知道訂單有什麼問題嗎?或者如果 隊列很長?訂單號:8028Vehicle代表:74JTag#: 200L049Description:2011 TAURUS FWD SELOrdered:08-AUG- 2010VIN 分配:VIN#:計劃:在 製作:製作:已開發票:發行時間:發貨:準備:稅務 位置:STATE OF密歇根州(20)國家保險:USOB狀態:050 - CLEAN計劃外訂單

正如我粘貼到記事本中的字符串++中這樣表示。

enter image description here

+1

Define * non-printable *。你在尋找某個ASCII代碼範圍內的字符嗎?如果是這樣? –

+0

@DarinDimitrov查看我的問題,編輯。 –

回答

8

您可以使用char.IsControl(c)來測試一個字符是否是控制(非打印)字符或不:

foreach (var c in str) 
{ 
    if (char.IsControl(c)) 
    { 
     Console.WriteLine("Found control character: {0}", (int)c); 
    } 
} 
+0

如何處理Unicode字符'LEFT-TO-RIGHT MARK'(U + 200E) – David

0

我寫了一個程序與谷歌和SO一些幫助。

該程序將打印ascii值和字符的位置是非打印字符。

class Program 
    { 
     static void Main(string[] args) 
     { 

      string text = @"I am an FMCC employee located in the Chicagoland area that currently has 2 available/active ManagementLease tags (non-incremental) and 1 currently utilized Sales Vehicle tag. I have a 2009 Sales vehicle now andhave ordered a replacement for that vehicle (2010 Taurus) per our current direction. I have not had a 2009 Model vehicle for either of my Management Lease tags in 2009. I was married in August of this year andordered a 2010 Flex on one of my Management Lease tags in September.My issue is that my wife's current vehicle is no longer serviceable, and the 2010 Flex has yet to be scheduled tobe built.My exception request is that I be allowed to take delivery and assume payments for a 2010 Taurus that is at alocal dealership and displayed on the ""Vehicles Available Now"" page on an interim basis until my 2010 Flex isdelivered. I appreciate that typically an employee cannot have two vehicles from the same model year on agiven Management Lease tag, but I was hoping an exception could be made due to my recent marriage andthe fact that I did not have a 2009 model year vehicle on any tags."; 
      for (int i = 0; i < text.Length; i++) 
      { 
       if (Char.ConvertToUtf32(text, i) < 32) 
       { 
        Console.WriteLine("position " + i + " " + text[i] + " => " + Char.ConvertToUtf32(text, i)); 
       } 
      } 
      Console.ReadLine(); 

     } 
    }