5

我有一个字符串,在 sql 中我测试过这个字符串包含不可打印的字符,但我找不到那些。

那么任何人都可以建议我如何通过传递此字符串在 C# 中查找和打印那些不可打印的字符?

我在八月份订购了 Taurus,但还没有预定,我只是想知道订单是否有问题?或者如果队列很长?订单号:8028Vehicle Rep:74JTag#: 200L049Description: 2011 TAURUS FWD SELOrdered: 08-AUG- 2010VIN Assigned:VIN#:Scheduled:In Production:Produced:Invoiced:Released:Shipped:Ready:Tax Location:STATE OF MICHIGAN (20 )被保险人状态:USOB 状态:050 - 清洁计划外订单

当我在记事本++中粘贴字符串时,它显示如下。

在此处输入图像描述

4

2 回答 2

10

您可以使用char.IsControl(c)来测试字符是否是控制(不可打印)字符:

foreach (var c in str)
{
    if (char.IsControl(c))
    {
        Console.WriteLine("Found control character: {0}", (int)c);
    }
}
于 2012-06-21T12:28:01.387 回答
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();

        }
    }
于 2012-06-21T12:43:49.710 回答