Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created October 22, 2013 03:54
Show Gist options
  • Select an option

  • Save masaru-b-cl/7094973 to your computer and use it in GitHub Desktop.

Select an option

Save masaru-b-cl/7094973 to your computer and use it in GitHub Desktop.
指定した文字数で文字列を分割(C#版)
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