Created
August 30, 2012 06:03
-
-
Save ritalin/3523074 to your computer and use it in GitHub Desktop.
最初に数字が出たところから末尾までの文字列を返す
This file contains hidden or 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
[Test] | |
public void _最初に数字が出たところから末尾までの文字列を返す() { | |
var needle = Enumerable.Range(0, 10).Select(c => (char)('0' + c)).ToArray(); | |
var text1 = "qazxdftyujh6olkmnbgfds"; | |
var i1 = text1.IndexOfAny(needle); | |
var actual1 = i1 >= 0 ? text1.Substring(i1) : ""; | |
Assert.That(actual1, Is.EqualTo("6olkmnbgfds")); | |
var text2 = "qsxcvhikol,kmjbgvf"; | |
var i2 = text2.IndexOfAny(needle); | |
var actual2 = i2 >= 0 ? text2.Substring(i2) : ""; | |
Assert.That(actual2, Is.Empty); | |
} |
This file contains hidden or 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
[Test] | |
public void _最初に数字が出たところから末尾までの文字列を返す_Linq馬鹿の場合() { | |
var needle = new HashSet<char>(Enumerable.Range(0, 10).Select(c => (char)('0' + c))); | |
var text1 = "qazxdftyujh6olkmnbgfds"; | |
var actual1 = string.Join("", text1.Cast<char>().SkipWhile(c => !needle.Contains(c))); | |
Assert.That(actual1, Is.EqualTo("6olkmnbgfds")); | |
var text2 = "qsxcvhikol,kmjbgvf"; | |
var actual2 = string.Join("", text2.Cast<char>().SkipWhile(c => !needle.Contains(c))); | |
Assert.That(actual2, Is.Empty); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment