在特定字符后的c#中修剪字符串 [英] trim string in c# after specific character

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

问题描述

大家好我想在一个特殊字符后修剪一个字符串..



假设字符串是str =arjunmenon.uk

i希望得到角色。并忽略rest.ie结果字符串必须是restr =arjunmenon

Hi guys i want to trim a string after a special character..

lets say the string is str="arjunmenon.uk"
i want to get the characters upto the . and ignore the rest.i.e the resultant string must be restr="arjunmenon"

推荐答案

试试这个



Try this

string str = "this is a #string";
string ext = str.Substring(0, str.LastIndexOf("#") + 1);







这应该有效。根据你的需要调整它。




THis should work. tweak it as pr your needs.


一旦我认为它适用于你,我会检查这个。

Hi check this once I think it works for u
string str = "asd.uk";
            if (str.Contains('.'))
            {
                int index = str.IndexOf('.');
                string result = str.Substring(0, index);
                Console.WriteLine("result: " + result);
            }


我希望以下链接可以帮助您

http://stackoverflow.com/ questions / 2522933 / how-to-find-a-string-contains-any-the-special-characters [ ^ ]
I hope the following link will help you
http://stackoverflow.com/questions/2522933/how-to-find-whether-a-string-contains-any-of-the-special-characters[^]


这篇关于在特定字符后的c#中修剪字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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