■■■

2016年4月11日月曜日

String文字列の最初または最後の文字列を調べて判定する方法

String文字列の最初または最後の文字列を調べて判定する方法
VB.NET
        ' 文字列
        Dim strText As String = "abcdefg"

        ' 最初の文字を調べる方法
        If strText.StartsWith("a") Then
            Console.WriteLine("最初の文字はa")
        End If

        ' 最後の文字を調べる方法
        If strText.EndWith("g") Then
            Console.WriteLine("最後の文字はg")

        End If


C#
            // 文字列
            string strText = "abcdefg";

            // 最初の文字を調べる方法
            if(strText.StartsWith("a"))
            {
                Console.WriteLine("最初の文字はa");
            }

            // 最後の文字を調べる方法
            if (strText.EndWith("g"))
            {
                Console.WriteLine("最後の文字はg");

            }

■■■