如何在使用C#.net之间删除字符 [英] How to remove characters between Using C#.net

查看:60
本文介绍了如何在使用C#.net之间删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想从字符串中删除某些字符.说输入看起来像这样:

Hello, I want to remove certain characters from a string. Say the input looks like this:

string ss="website15(3)\\.net(5)";

但我希望它看起来像

website15\\.net

我可以使用哪些选项?

推荐答案

请参考以下链接:

如何使用C#.net在这些字符之间删除 [ ^ ]
Please refer below link:

How to remove between those character using C#.net[^]


有效地,您面临两种选择:

1.使用字符串索引找到第一个(的位置,然后使用它找到紧随其后的)(使用第一个(的索引(作为搜索的起始位置).索引,您将使用子字符串检索直到(的部分,然后从)到末尾.重复此过程,直到没有更多的( )序列.
2.使用正则表达式搜索(...)部分,然后将其替换为空字符串.

在编写和测试正则表达式时,我使用 Expresso [
Effectively you face two choices:

1. Use string indexes to find the position of the first ( and then use that to find the ) that follows it (use the index of the first ( as the starting position for your search). Now that you have the indexes, you would use substring to retrieve the part up to the (, and then from the ) to the end. Repeat this process until you have no more ( ) sequences.

2. Use a regular expression to search for the (...) parts, and replace them with an empty string.

When I''m writing and testing regular expressions, I use Expresso[^] to help me.


这篇关于如何在使用C#.net之间删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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