字符串的行号 [英] line number of string

查看:103
本文介绍了字符串的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中的文本文件中找到字符串的行号?

How can i find the line number of string in textfile in c#?

推荐答案

请参考一些链接:
C#行计数文件方法 [ ^ ]
C#正则表达式食谱-计算文本行数 [搜索文字使用c#文件并显示行号 [ C#将行号添加到文本文件 [ ^ ]
一次读取一行文本文件(Visual C#) [ ^ ]
Please refer some links:
C# Line Count File Method[^]
C# Regular Expression Recipes—Counting Lines of Text[^]

Similar Discussion:
search text file using c# and display the line number[^]

Have a look on these links for reference:
C# add line numbers to a text file[^]
Reading a Text File One Line at a Time (Visual C#)[^]


计数换行符.




您可能会:
Counting newlines.




You might:
  1. 0初始化lineno.
  2. 读取一行,递增lineno.
  3. 如果在行内找到该字符串,则退出(lineno包含正确的字符串行号),否则转到第2点.
  1. Initialize lineno with 0.
  2. Read a line, increment lineno.
  3. If you find the string inside the line the exit (lineno contains the correct string line number) else go to point 2.


请注意,您还应该处理在找到字符串之前结束文件"的情况.


Note you should also handle the ''end-of-file before the string is found'' condition.


Mohsen,

看看我对完全/匹配问题的回答.该解决方案会通知您行号.
Mohsen,

Have a look at my answer to exact/match question. That solution inform you the line number.


这篇关于字符串的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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