如何使用c#修剪字符串? [英] how to trim a string using c#?

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

问题描述

亲爱的先生,

i有一个字符串变量如下



string ts =2.00:00:00;

i希望剪切此字符串并仅将2存储到另一个字符串变量中。

i想做字符串剪切=2





plz help ...

解决方案

  string  s =   2.00:00:00; 
//
//在空格上拆分字符串
// ...这会将所有单词分开。
//
string [] words = s.Split(' 。');

words [ 0 ] 得到结果: 2


  string  ts =   2.00:00:00< /跨度>; 

string [] split = ts。( new Char [] {< span class =code-string>'
。'});

if (split.length > 0
{
Console.Write(split [ 0 ]);
}


另一种选择是 SUBSTRING



例如:

  string  newword =   2.00:00:00; 
string cut = newword.Substring( 0 1 );


dear sir,
i have one string variable like below

string ts="2.00:00:00";
i want to cut this string and store only "2" into another string variable.
i want to do string cut="2"


plz help...

解决方案

string s = "2.00:00:00";
    //
    // Split string on spaces.
    // ... This will separate all the words.
    //
    string[] words = s.Split('.');

words[0] get the result : 2


string ts = "2.00:00:00";

string[] split = ts.(new Char [] {'.'});

if(split.length > 0)
{
    Console.Write(split[0]);
}


Another option is SUBSTRING

Eg:

string newword = "2.00:00:00";
string cut= newword.Substring(0, 1);


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

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