简体   繁体   English

C#比较两个字符串,其中一个具有唯一的indenifier

[英]C# Comparing two strings, one with unique indenifiers

First of all I'd like to mention that I'm new to programming and this sight so I'm still an infant in this world, however, I have a problem. 首先,我想提一下,我是编程和该领域的新手,所以我还是这个世界的婴儿,但是,我有一个问题。

I have to make code that can compare two strings but the second string (from a file) will have unique identifiers within it. 我必须编写可以比较两个字符串的代码,但是第二个字符串(来自文件)将在其中具有唯一的标识符。 For example: 例如:

first string: 第一个字符串:

I have 10 cats and their fur is #000000

Second string from a file: 文件中的第二个字符串:

I have <d> cats and their fur is <h>

Although I probably don't need to explain, 'd' is for numbers or decimal and 'h' for hex. 尽管我可能不需要解释,但“ d”代表数字或十进制,而“ h”代表十六进制。 There are also 's' and 'a' associated to ASCII. 还有与ASCII相关联的“ s”和“ a”。

What's supposed to happen is that the first string can have any different number which can be of different length and/or Hex when the data comes in but the rest of the message stays the same, EG 应该发生的是,当输入数据时,第一个字符串可以具有任何不同的数字,这些数字可以具有不同的长度和/或十六进制,但是消息的其余部分保持不变,例如

I have 1500 cats and their fur is #000000

the code will still match the two strings as True matches as it'll effectively ignore anything that is an int and hex. 该代码仍将匹配两个字符串,因为True匹配,因为它将有效地忽略所有为int和hex的内容。 (this identifiers are User defined so they can be anywhere in any string). (此标识符是用户定义的,因此它们可以在任何字符串中的任何位置)。

The end game is that if it finds a relative match the code will change the colour of the text in the app among other things. 最终的结果是,如果找到相对匹配的代码,则代码将更改应用程序中文本的颜色。 it's basically to highlight errors in a log file. 基本上是在日志文件中突出显示错误。

I've searched High an low on Stackflow and looked into Regex and string comparisons. 我搜索了Stackflow的高位,并查看了正则表达式和字符串比较。 I'm currently going to make a start on the code, however, would like some input/help. 我目前要开始编写代码,但是,需要一些输入/帮助。

Obviously I'm not asking for something to be written for me, just to be pointed in the right direction so I can learn. 显然,我并不是要为我写些东西,只是要指出正确的方向,以便我学习。

Many thanks in advance! 提前谢谢了! And apologies if there is a similar post out there, but alas I couldn't find it if there is. 抱歉,如果那里有类似的帖子,但可惜我找不到它。

If I understand it correctly I think I would solve this by replacing the <d> etc. by a RegEx expression. 如果我理解正确,我想我可以通过用RegEx表达式替换<d>等来解决此问题。 Then use that RegEx to replace the values by an empty string. 然后使用该RegEx用空字符串替换值。 That way you can compare them without the values. 这样,您可以比较它们而没有值。

Hope that makes sense. 希望有道理。 I didn't include any code because you asked for just some directions. 我没有包含任何代码,因为您只问了一些指示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM