Created
October 22, 2013 03:54
-
-
Save masaru-b-cl/7094973 to your computer and use it in GitHub Desktop.
指定した文字数で文字列を分割(C#版)
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[] { | |
| new string(value.Take(size).ToArray()), | |
| new string(value.Skip(size).ToArray()) | |
| }; | |
| } | |
| } | |
| [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