Current location - Quotes Website - Team slogan - How does C# take out the digital part of a piece of text and save it as an array?
How does C# take out the digital part of a piece of text and save it as an array?
Take out the IP address and port number according to your requirements and save it as an array. You need to match the IP address and port number with a regular expression.

The specific procedures are as follows

Use the system;

Use the system. Text. Regular expression;

Namespace MatchSocketApplication {

Class MatchSocketClass{

Static void Main(string[] args){

String[]xx = new string [100];

int count = 0;

String s = "enable: true eddy:/47.102.102.240: 45808 Eternal Life:/182.244.227.3: 38215 Loulan:/2227.3.

MatchCollection mc =Regex。 Match (s, @"\d+\. \d+\。 \d+\。 \ d+:\ d+";

Foreach (matching m in mc) {

Xx[ count] = m. Group [0]. Value;

count++;

}

for(int I = 0; I < count; i++){

Console. WriteLine(xx[I]);

}

Console. read key();

}

}

}