如何使用子串功能 [英] how to use the substring function

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

问题描述

变量包含字符串值.我需要使用该字符串的最后两个字符.我可以为此目的使用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?

推荐答案

是的,您可以使用substring函数.请参见此处 [
Yes you can use the substring function. See here[^] for an example.


为回答您的问题,我做了以下工作:我只计算了两个最常用的标准.NET库的所有公共类型的公共成员总数:"mscorelib"和"System.Core",两者都覆盖了名称空间System.我不算类型,只算类型成员,例如System.String.Substring.

结果如下:

    < il> mscorelib:39882个公共成员
    < il> System.Core:6811个公共成员
    < il>总计:46693个公共成员
To reply to your question, I''ve done the following: I counted total number of public members of all public types of just two most used standard .NET libraries: "mscorelib" and "System.Core", both covering the name space System. I did not count the types, only the type members, such as System.String.Substring.

Here are the results:

    <il>mscorelib: 39882 public members
    <il>System.Core: 6811 public members
    <il>Total: 46693 public members
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



—SA



—SA


尝试
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


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

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