C# 使用 Strings

  • 2273
  • 0

摘要:C# 使用 Strings

直接使用


using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;

即可使用

自行撰寫類別


public static int InStr	(String String1, String String2,	 [Optional][DefaultValue CompareMethod.Binary)] CompareMethod Compare)
{
return InStr(1, String1, String2, Compare);
}

public static int InStr(int Start, String String1, String String2,[Optional][DefaultValue(CompareMethod.Binary)] CompareMethod Compare)
{
if(String1 == null || String1.Length == 0)
{
return 0;
}
if(String2 == null || String2.Length == 0)
{
return Start;
}
if(Start >= String1.Length)
{
return 0;
}
if(Compare == CompareMethod.Binary)
{
return (CultureInfo.CurrentCulture.CompareInfo.IndexOf(String1, String2, Start - 1,CompareOptions.Ordinal) + 1);
}
else
{
return (CultureInfo.CurrentCulture.CompareInfo.IndexOf(String1, String2, Start - 1,CompareOptions.IgnoreWidth |CompareOptions.IgnoreKanaType | CompareOptions.IgnoreCase) + 1);
}
}