Created
October 22, 2013 03:58
-
-
Save masaru-b-cl/7095022 to your computer and use it in GitHub Desktop.
文字列を指定した文字数で分割(C#版) ※非LINQ
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
| using System; | |
| using System.Linq; | |
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| namespace UnitTestProject1 | |
| { | |
| public static class StringExtensions | |
| { | |
| public static string[] Nyan(this string value, int size) | |
| { | |
| return new[] { value.Substring(0, size), value.Substring(size) }; | |
| } | |
| } | |
| [TestClass] | |
| public class UnitTest1 | |
| { | |
| [TestMethod] | |
| public void TestMethod1() | |
| { | |
| string[] result = "0123456789".Nyan(3); | |
| Assert.AreEqual("012", result[0]); | |
| Assert.AreEqual("3456789", result[1]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment