Last active
August 26, 2020 04:06
-
-
Save chuongmep/79712c483c121be4313af95be9119640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Folder funtion Number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Return Number Join In String Example : (hello 23 my 28) return [2328] | |
/// </summary> | |
/// <param name="str"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> NumberInString(string str) | |
{ | |
string b = string.Empty; | |
string[] spearator = {"."}; | |
List<double> result = new List<double>(); | |
for (int i=0; i< str.Length; i++) | |
{ | |
if (char.IsDigit(str[i])) | |
b += str[i]; | |
} | |
if (b.Length > 0) | |
{ | |
if (int.TryParse(b,out int int32)) | |
{ | |
result.Add(int32); | |
} | |
else if (double.TryParse(b,out double val)) | |
{ | |
result.Add(val); | |
} | |
} | |
return result.Select(x => x.ToString(CultureInfo.InvariantCulture)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Return Number split In String : Example : (hello 23 my 28) return [23,28] | |
/// </summary> | |
/// <param name="str"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> NumberInStrings (string str) | |
{ | |
var nums = new List<double>(); | |
var start = -1; | |
for (int i = 0; i < str.Length; i++) | |
{ | |
if (start < 0 && char.IsDigit(str[i])) | |
{ | |
start = i; | |
} | |
else if (start >= 0 && !char.IsDigit(str[i])) | |
{ | |
nums.Add(double.Parse(str.Substring(start, i - start))); | |
start = -1; | |
} | |
} | |
if (start >= 0) | |
nums.Add(double.Parse(str.Substring(start, str.Length - start))); | |
return nums.Select(x=>x.ToString(CultureInfo.InvariantCulture)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment