如何从字符串生成器中删除数据 [英] How to remove data from string builder

查看:91
本文介绍了如何从字符串生成器中删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我都需要从文本文件中删除特定数据.我已经编写了一些代码来删除我的确切数据,但是现在我有点困惑,因为删除特定数据可以帮助任何人.

最初,这是我存储在Stringbuilder中的文本文件中的数据

Hi i all having a requirement to delete particular data from a text file. I have written some code to get my exact data to remove but now i am little bit confused in removing that particular data can any one help me.

Initially this is my data in text file where i am storing to a Stringbuilder

101 111111111 1111111111110150105A094101                                                      

52201               1                   1         PPD1         111015111015   1111000020000001

6241110000251                00000000011              1                     1 0111000020000001

822000000100111000020000000000000000000000011                                  111000020000001

52251               1                   1         PPD1         011015111015   1111000020000002

6281110000251                00000000011              1                     1 0111000020000002

822500000100111000020000000000010000000000001                                  111000020000002

9000002000001000000020022200004000000000001000000000001                                       



现在通过使用某些代码,我正在删除数据,即假设我想从存在的5到8中删除.我将其存储到另一个StringBuilder,如下所示



Now by using certain code i am getting the data to delete i.e assume i would like to delete from 5 to 8 which exists. I am storing this to another StringBuilder as follows

52251               1                   1         PPD1         011015111015   1111000020000002

6281110000251                00000000011              1                     1 0111000020000002

822500000100111000020000000000010000000000001                                  111000020000002



我想从我拥有的主要Stringbuilder中删除它.这是正确的过程,还是有更好的方法让我知道?



I would like to remove this from the main Stringbuilder i am having. Is this the correct process or if any better way let me know

推荐答案

您可以尝试使用第二个StringBuilder的内容,通过以下方式将其从第一个StringBuilder中删除使用替换 [
You could try using the content of the second StringBuilder to remove it from the first one by using the Replace[^] method.

It would look something like:
mainStringBuilder.Replace(anotherStringBuilder.ToString(), "");


是的-从StringBuilder中删除应该比创建一个新的效率更高.如果您知道第一个字符索引和长度(显然可以从总长度和字符索引中得出),则可以使用StringBuilder.Remove方法 [
Yes - deleting from a StringBuilder should be a lot more efficient that creating a new one. If you know the first character index and the length (which you can obviously work out from the total length and the character index) then you can just use the StringBuilder.Remove method[^]


这篇关于如何从字符串生成器中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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