Skip to content

Instantly share code, notes, and snippets.

@shun115
Created February 17, 2011 02:40
Show Gist options
  • Save shun115/830842 to your computer and use it in GitHub Desktop.
Save shun115/830842 to your computer and use it in GitHub Desktop.
C# LastIndexの不思議な挙動
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace TestCodes
{
[TestFixture]
public class LastIndexTest
{
[Test]
public void LastIndex()
{
Assert.AreEqual(-1, "馬".LastIndexOf("("));
Assert.AreEqual(-1, "ゝ".LastIndexOf("("));
Assert.AreEqual(0, "(馬".LastIndexOf("("));
Assert.AreEqual(0, "(".LastIndexOf("("));
Assert.AreEqual(0, "(".LastIndexOf('('));
Assert.AreEqual(1, "(ゝ馬".LastIndexOf("("));
Assert.AreEqual(1, "(ゝ".LastIndexOf("("));
Assert.AreEqual(0, "(ゝ".LastIndexOf('('));
}
}
}
@shun115
Copy link
Author

shun115 commented Feb 17, 2011

普通はこうだよな。。。


Python 2.6.6 (r266:84292, Feb 10 2011, 17:57:48)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "馬".rfind("(")
-1
>>> "ゝ".rfind("(")
-1
>>> "(馬".rfind("(")
0
>>> "(".rfind("(")
0
>>> "(".rfind('(')
0
>>>
>>> "(ゝ馬".rfind("(")
0
>>> "(ゝ".rfind("(")
0
>>>
>>> "(ゝ".rfind('(')
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment