이 항목은 아직 평가되지 않았습니다.- 이 항목 평가

String.Substring 메서드 (Int32)

이 인스턴스에서 부분 문자열을 검색합니다. 부분 문자열은 지정된 문자 위치에서 시작됩니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

public string Substring (
	int startIndex
)
public String Substring (
	int startIndex
)
public function Substring (
	startIndex : int
) : String

매개 변수

startIndex

이 인스턴스의 부분 문자열에 있는 시작 문자 위치입니다.

반환 값

이 인스턴스의 startIndex에서 시작하는 부분 문자열에 해당하는 String 개체이거나, startIndex가 이 인스턴스의 길이와 같으면 Empty입니다.
예외 형식조건

ArgumentOutOfRangeException

startIndex가 0보다 작거나 이 인스턴스의 길이보다 큰 경우

인덱스는 0부터 시작합니다.

다음 코드 예제에서는 문자열에서 부분 문자열을 얻는 방법을 보여 줍니다.

using System;

public class SubStringTest {
    public static void Main() {

        string [] info = {"Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F"};
        int found = 0;

        Console.WriteLine("The initial values in the array are:");
        foreach (string s in info)
            Console.WriteLine(s);

        Console.WriteLine("{0}We want to retrieve only the key information. That is:", Environment.NewLine);        

        foreach (string s in info) {
            found = s.IndexOf(":");
            Console.WriteLine(s.Substring(found + 1).Trim());
        }
    }
}

import System.*;

public class SubStringTest
{
    public static void main(String[] args)
    {
        String info[] =  { "Name: Felica Walker", "Title: Mz.",
            "Age: 47", "Location: Paris", "Gender: F" };
        int found = 0;

        Console.WriteLine("The initial values in the array are:");
        for (int iCtr = 0; iCtr < info.get_Length(); iCtr++) {
            String s = info[iCtr];
            Console.WriteLine(s);
        }

        Console.WriteLine("{0}We want to retrieve only the key information." 
            + " That is:", Environment.get_NewLine());
        for (int iCtr = 0; iCtr < info.get_Length(); iCtr++) {
            String s = info[iCtr];
            found = s.IndexOf(":");
            Console.WriteLine(s.Substring(found + 1).Trim());
        }
    } //main
} //SubStringTest

import System;

public class SubStringTest {
    public static function Main() : void {

        var info : String [] = ["Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F"];
        var found : int = 0;

        Console.WriteLine("The initial values in the array are:");
        for (var i : int in info)
            Console.WriteLine(info[i]);

        Console.WriteLine("{0}We want to retrieve only the key information. That is:", Environment.NewLine);        

        for (i in info) {
            found = info[i].IndexOf(":");
            Console.WriteLine(info[i].Substring(found + 1).Trim());
        }
    }
}
SubStringTest.Main();

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원
이 정보가 도움이 되었습니까?
(1500자 남음)

커뮤니티 추가 항목

추가
© 2013 Microsoft. All rights reserved.