[英]How to Split an ANSI string with unknown characters returned from OpenVMS in C#
I have a method that I've written in C# that connects to OpenVMS, runs a command and then returns the output. 我有一个用C#编写的方法,该方法连接到OpenVMS,运行命令,然后返回输出。
One of the DCL procedures it runs returns a "form" in the form of a string which has all sorts of ANSI encoding in it. 它运行的DCL过程之一以字符串形式返回“形式”,其中包含各种ANSI编码。
What I wish to do is to split the returned string into an array based on the ANSI escape character as a delimiter so that I can further sort it and build a display later on. 我希望做的是将返回的字符串拆分为一个基于ANSI转义字符作为分隔符的数组,以便我可以对其进行进一步排序并稍后建立显示。
The problem i'm having is the escape character doesn't look like its being recognized. 我遇到的问题是转义字符看起来不像被识别。 When I inspect the string in visual studio I can see the standard ANSI formatting with an arrow pointing left that looks like this: ← between each entry. 当我在Visual Studio中检查字符串时,我可以看到标准ANSI格式,带有指向左侧的箭头,如下所示:每个条目之间的←。 This is the escape character. 这是转义字符。
If I paste the same string into notepad++ it shows up as ESC. 如果我将相同的字符串粘贴到notepad ++中,它将显示为ESC。
I've tried doing a split on the string with \\033 being the delimiter, but that didn't work, I've also tried pasting the ESC character into a variable but it simply pastes an empty space. 我尝试使用\\ 033作为分隔符对字符串进行拆分,但这没有用,我还尝试将ESC字符粘贴到变量中,但它只是粘贴了一个空格。
So I'm wondering how do I find out what character code this escape character is using so that I can use it in my split. 所以我想知道如何找出此转义字符使用的字符代码,以便可以在拆分中使用它。
Id post a screenshot but I don't have the rep to do that apparently. Id发布了屏幕截图,但显然我没有代表这样做。
edit: this is whats being returned: 编辑:这是返回什么:
[02;27HDIVIDEND SETUP 11:25 Mon, 21 Jul 2014[04;05HCurrent attach point : VOD_TIM[07;05H Code Description[07;60HDate Run
Its not showing up as a character on StackOverflow but if you imagine the character is infront of each of the segments starting with a [ 它不会在StackOverflow上显示为字符,但是如果您认为字符在每个以[[
Edit 2: OKay se we've established that the int char code is 27 so the issue now is how do I use that in my split? 编辑2:好的,我们已经确定int char代码为27,所以现在的问题是如何在拆分中使用它?
You can try out the splitting your string via Regex
, something like this: 您可以尝试通过Regex
分割字符串,如下所示:
string input = YOUR_STRING_HERE;
string pattern = @"\033";
string[] substrings = Regex.Split(input, pattern);
foreach (string match in substrings)
{
Console.WriteLine("'{0}'", match);
}
Update: 更新:
You can use the \\e
symbol for the ESC
character in Regex
in .Net, see the full list of escape characters in Regex
here . 您可以使用\\e
符号的ESC
字符Regex
在.NET中,看到的转义字符的完整列表中Regex
这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.