字符串运算 [英] string operation

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

问题描述

你好,

我要删除还是删除字符串的一部分?
我需要编写一个方法或执行一些将读取str1和str2的操作.找到str2时,它将从str1中删除它并更新str1.

更清楚地说,

可以说我有:

string str1 ="Lorem Ipsum只是印刷和排版行业的伪文本.从1500年代开始,Lorem Ipsum一直是该行业的标准伪文本,当时未知的打印机拿起一个厨房并将其打乱成一个类型标本."

string str2 =自1500年代以来,Lorem Ipsum一直是该行业的标准伪文本,"

最终字符串应为;

str1 ="Lorem Ipsum只是印刷和排版行业的伪文本.当未知的打印机拿起一个样板间并将其打乱成一本样本册时.";

我不能使用子字符串方法,因为str2会因为输入字符串而发生变化.

Hello,

I want to delete or remove a part of a string?
I need to write a method or do something which will read the str1 and str2. when it finds the str2, it will delete it from str1 and update the str1.

To be more clear,

Lets say I have:

string str1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."

string str2 = "Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s, "

The final string should be;

str1 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. when an unknown printer took a galley of type and scrambled it to make a type specimen book."";

I cant use substring method because str2 can change because of the input string.

推荐答案

try:
try:
str1 = str1.Replace(str2, "");

http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx [^ ]

[edit]不需要将str1声明为字符串... Doh![/edit]

http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^]

[edit]Don''t need the declaration of str1 as a string... Doh![/edit]


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

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