문자열 위치찾기
· 배운 것 · 2분 읽기
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string factMessage = "Extension methods have all the capabilities of regular static methods.";
//문자열안에서 특정문자열이 있다면 처음 idx return, c++의 find
int first = factMessage.IndexOf("methods") + "methods".Length;
int last = factMessage.LastIndexOf("methods");
//문자열 끊기, 여기에서는 특정문자열이 없는 부분만 끊었다. c++의 string.substr()
string str2 = factMessage.Substring(first, last - first);
Console.WriteLine("{0}, {1}", first, last);
Console.WriteLine(str2);
Console.WriteLine(factMessage.Length);
}
}
}