如何从asp.net中的字符串中删除字符串的某些部分 [英] How to remove some portion of string from a string in asp.net

查看:261
本文介绍了如何从asp.net中的字符串中删除字符串的某些部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个字符串,如

Hi All,

I have a string as

Label1.Text="Name : Mohd Wasif";


我只想要Mohd wasif

请帮帮我.

谢谢你
Mohd Wasif


I want only Mohd wasif

please help me.

Thanking you
Mohd Wasif

推荐答案

尝试一下,

Try out this,

str1.substring(7);


除了现有答案外,还请注意:字符串是不可变的 .不管您使用字符串是什么,都永远不会删除",添加"或修改"字符串中的任何内容.而是创建了一个全新的字符串.重要的是要知道它的性能和对多线程的影响.例如,重复"+"是非常糟糕的.字符串的可变版本是System.Text.StringBuilder.使用它来提高性能,只需使用System.Text.StringBuilder.ToString()即可转换为字符串.

—SA
Just a note, in addition to existing answers: strings are immutable. No matter you do with strings, you never "remove", "add" or "modify" anything it a string. Instead, a brand-new string is created. It''s important to know due to its performance and multithreading implications. For example, repeating "+" is very bad. A mutable version of string is System.Text.StringBuilder. Use it for performance, convert to string simply using System.Text.StringBuilder.ToString().

—SA


最好的办法是在分隔符:"
上分割字符串
the best thing would be to split your string on a seperator ":"
string s = "Name : Mohd Wasif";
string[] words = s.Split( '':''); // split string on seperator

Label.Text = words[1].Trim( ); // assign trimmed value without leading or trailing spaces


这篇关于如何从asp.net中的字符串中删除字符串的某些部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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