使用奇数分隔符读取文本文件的一部分 [英] Reading a part of a text file with odd delimiters

查看:76
本文介绍了使用奇数分隔符读取文本文件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我目前正在使用C#程序,正在尝试解析文本文件的某些部分,并根据与之接触的字符生成动态对话.

要显示的对话类型用@或!表示.符号,对话文本用〜符号表示,下面是其中一个文件的一些示例文本.

#200<br />
@001 Enter the name of the INSURANCE COMPANY:<br />
~Enter the name of the insurance company. Should match name on<br />
~policy/declarations.<br />
@002 Enter the title of the signatory for insurance company.<br />
~Enter the title of the person sending the notice. For example:<br />
~claims manager.<br />
@003 Enter the name of the INSURED:<br />
~Enter the name of the insured. Should match the name on policy<br />
~declarations.<br />
@004 Enter the street mailing address of the insured:<br />
~Enter the street mailing address for the insured.<br />
@005 Enter the city, state and zip code of the insured:<br />
~Enter the city, state and zip code of the mailing address of<br />
~the insured.<br />
@006 Enter the salutation for the letter:<br />
~Enter the salutation for use in the letter.  Include the greeting<br />
~as well as name of the recipient, for example: Dear <br />
~Mr. Policy_holder.<br />
@007 Enter the name of the claimant:<br />
~Enter the name of the claimant or claimants.<br />
!008 Enter the total available limits of coverage:<br />
~Enter in dollar format the available coverage provided for the<br />
~incident.<br />
#end control section<br />
#200




如果有人对如何完成此操作有任何建议,将不胜感激.如果定界符始终是第一个字符,那么您只需要读取该第一个字符,然后对它进行拆分就可以处理该字符.否则,您可以使用string在每一行中搜索它.

Hi,

I''m currently working on a C# program and am trying to parse some parts of a text file and generate a dynamic dialogue based on the character it comes in contact with.

The type of dialogue to be displayed is denoted by @ or ! symbols, and the dialogue text is denoted by a ~ symbol, below is some sample text from one of the files.

#200<br />
@001 Enter the name of the INSURANCE COMPANY:<br />
~Enter the name of the insurance company. Should match name on<br />
~policy/declarations.<br />
@002 Enter the title of the signatory for insurance company.<br />
~Enter the title of the person sending the notice. For example:<br />
~claims manager.<br />
@003 Enter the name of the INSURED:<br />
~Enter the name of the insured. Should match the name on policy<br />
~declarations.<br />
@004 Enter the street mailing address of the insured:<br />
~Enter the street mailing address for the insured.<br />
@005 Enter the city, state and zip code of the insured:<br />
~Enter the city, state and zip code of the mailing address of<br />
~the insured.<br />
@006 Enter the salutation for the letter:<br />
~Enter the salutation for use in the letter.  Include the greeting<br />
~as well as name of the recipient, for example: Dear <br />
~Mr. Policy_holder.<br />
@007 Enter the name of the claimant:<br />
~Enter the name of the claimant or claimants.<br />
!008 Enter the total available limits of coverage:<br />
~Enter in dollar format the available coverage provided for the<br />
~incident.<br />
#end control section<br />
#200




If anybody has any advice on how to accomplish this it will be greatly appreciated.

解决方案

You can read this as an array of lines with File.ReadAllLines. If the delimiter is always the first character, then you just have to read that first character, and split on it to work out what to do with it. Otherwise, you can search for it in each line, using string.Split perhaps ?


这篇关于使用奇数分隔符读取文本文件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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