帮我解析以下文件格式 [英] Help me parsing the following file format

查看:81
本文介绍了帮我解析以下文件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析以下格式的第三方文本文件

I need to parse third party text file in the following format

WE BUY  : 10 000.00 USD                      
VALUE   : 281210
RATE    : 30.2600

所以一般的模式是

TAG,一些分隔符,:,someseparator,VALUE

让我们说我从File.ReadAllLines开始,所以我要处理个别行.

Let;s say i started with File.ReadAllLines so I am dealing with individual lines.

解析值的最佳方法是什么?

What is the best way to parse values?

更新

我没有该格式的任何文档,但可以说它是基于位置的.

I don't have any documentation for the format but let's say that it is position-based.

1):"始终是字符串中的第9个字符, 2)VALUE是第11个字符. 3)未使用的空格填充有空格字符.

1) ":" is always 9th charcter in the string, 2) VALUE is 11th character. 3) Unused spaces are filled with space character.

让我们来谈谈这种格式.

Let's talk about that format.

更新2

我正在考虑RegEx是否在这里更好?例如,假设我有一个子任务 找到

I am thinking about if RegEx is better here? For instance let's say I have a subtask find

RATE : 30.2600

提取以第11个字符开头的30.2600

in the whole text and extract 30.2600 given that is starts with 11th character

推荐答案

对于每行:

   string[]  parts = line.Split(':');
   // assert parts.Length == 2
   string tag = parts[0].Trim();
   string[] values = parts[1].Split(' ', SplitOptions.NoDupes);  // or ','

这篇关于帮我解析以下文件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆