本文介绍了如何使用子串功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
变量包含字符串值.我需要使用该字符串的最后两个字符.我可以为此目的使用substring函数吗?如果可以,可以给我一个简单的例子.
还是有另一种方法?
A variable contains a string value. i need to take the last two characters of that string. can i use the substring function for this purpose?if so can any one give me a simple example for that.
or is there another way of doing this?
推荐答案
using System;
using System.Reflection;
//...
static int CountPublicMembers(Assembly assembly) {
int result = 0;
Type[] types = assembly.GetTypes();
foreach (Type type in types)
result += type.GetMembers().Length;
return result;
} //CountPublicMembers
static void CountAll() {
Assembly mscorelib = typeof(System.String).Assembly;
Assembly systemCore = typeof(System.Action).Assembly;
int iMscorelib = CountPublicMembers(mscorelib);
int iSystemCore = CountPublicMembers(systemCore);
System.Console.WriteLine(
"{0}+{1} = {2}",
iMscorelib, iSystemCore,
iMscorelib + iSystemCore);
} //CountAll
string str = "YourStringValues";
str = str.Substring(str.Length - 2); // Passing parameter Zero based starting character position of substring.
Console.WriteLine(str); // Print Last two Character eg:- es
输出:-es
output :- es
这篇关于如何使用子串功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!