在C#中切割字符串 [英] Cutting a string in c#

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

问题描述

你好!!!谁能帮我如何在C#中切割字符串?这是"mymail@gmail.com"中的实例,我想在"@"之后剪切gmail.com.

Tnx为您提供答案...

Hello!!! Can anyone help me how to cut string in c#? This is the instance in "mymail@gmail.com" i want to cut gmail.com after the "@".

Tnx for your answers...

推荐答案

尝试以下操作:-

try this:-

string[] strEmail= string.Split("mymail@gmail.com","@");



其中strEmail是字符串Array和

strEmail [1]等于"gmail.com".



where strEmail is the string Array and

strEmail[1] will be equal to "gmail.com".


要么:
string sample = "mymail@gmail.com";
string[] parts = sample.Split('@');


或:


Or:

string sample = "mymail@gmail.com";
string localAddress = sample.SubString(0, sample.IndexOf('@'));


首先将其分为两部分:


The first will break it into two parts:

"mymail"
"gmail.com"

第二个将删除"@"及其所有内容.是对的.

The second will remove the "@" and everything to it''s right.


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

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