开发者

How to get substrings from a string

开发者 https://www.devze.com 2023-02-01 08:39 出处:网络
for example string test = \"extract substring from a string\"; // e开发者_开发知识库xtract this in to

for example

string test = "extract substring from a string"; // e开发者_开发知识库xtract this in to

extract

substring

from

a

string

in .net2 thank you


You're looking for String.Split.


test.Split(" \t\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)


The substring function has 2 overloads as follows:

  1. Substring(int startIndex)

  2. Substring(int startIndex, int length)

1st type of Substring overloaded function accepts only single parameter as integer type starting index of the character position in the specified string. 2nd type Substring overloaded function accepts two types of parameters, first as integer type starting index of the character position in the string and second parameter as the integer type length or the number of characters to be returned as the substring of specified string.


string t = string.join("\n", test.split(" "));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号