/// <summary> /// 指定した文字列内の指定した文字列を別の文字列に置換する。 /// </summary> /// <param name="input">置換する文字列のある文字列。</param> /// <param name="oldValue">検索文字列。</param> /// <param name="newValue">置換文字列。</param> /// <param name="count">置換する回数。負の数が指定されたときは、すべて置換する。</param> /// <param name="compInfo">文字列の検索に使用するCompareInfo。</param> /// <param name="compOptions">文字列の検索に使用するCompareOptions。</param> /// <returns>置換された結果の文字列。</returns> private static string StringReplace( string input, string oldValue, string newValue, int count, System.Globalization.CompareInfo compInfo, System.Globalization.CompareOptions compOptions) { if (input == null || input.Length == 0 || oldValue == null || oldValue.Length == 0 || count == 0) { return(input); } if (compInfo == null) { compInfo = System.Globalization.CultureInfo.InvariantCulture.CompareInfo; compOptions = System.Globalization.CompareOptions.Ordinal; } int inputLen = input.Length; int oldValueLen = oldValue.Length; System.Text.StringBuilder buf = new System.Text.StringBuilder(inputLen); int currentPoint = 0; int foundPoint = -1; int currentCount = 0; do { //文字列を検索する foundPoint = compInfo.IndexOf(input, oldValue, currentPoint, compOptions); if (foundPoint < 0) { buf.Append(input.Substring(currentPoint)); break; } //見つかった文字列を新しい文字列に換える buf.Append(input.Substring(currentPoint, foundPoint - currentPoint)); buf.Append(newValue); //次の検索開始位置を取得 currentPoint = foundPoint + oldValueLen; //指定回数置換したか調べる currentCount++; if (currentCount == count) { buf.Append(input.Substring(currentPoint)); break; } }while (currentPoint < inputLen); return(buf.ToString()); }
static private void getBoneOrder(ref int order, ref BoneCategory category, string source, string query, BoneCategory setCategory = BoneCategory.Other) { System.Globalization.CompareInfo ci = System.Globalization.CultureInfo.CurrentCulture.CompareInfo; //source内にqueryが含まれていた場合、序数とカテゴリを代入 if (0 <= ci.IndexOf(source, query, System.Globalization.CompareOptions.IgnoreWidth)) { order = orderCount; category = setCategory; } orderCount++; }
public bool GetAutoCompleteList(FindType Findtype = FindType.Including) { bool flg = false; bool flg1 = false; listBox.Items.Clear(); //文字列比較に現在のカルチャを使用する System.Globalization.CompareInfo ci = System.Globalization.CultureInfo.CurrentCulture.CompareInfo; if (_AutoCompleteItems != null) { if (_CurrentText != "") { foreach (String s in _AutoCompleteItems) { switch (Findtype) { case FindType.Including: if (ci.IndexOf(s, _CurrentText, System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreWidth | System.Globalization.CompareOptions.IgnoreCase) > -1) { flg = true; } break; //case FindType.Match: // if (StrConv(_CurrentText, VbStrConv.Wide) = StrConv(s, VbStrConv.Wide)) // flg = true; // break; case FindType.Initials: //if (ci.IsPrefix(s, _CurrentText, System.Globalization.CompareOptions.None))//, System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreWidth | System.Globalization.CompareOptions.IgnoreCase)) if (s.StartsWith(_CurrentText, StringComparison.OrdinalIgnoreCase)) { flg = true; } break; case FindType.Ending: if (ci.IsSuffix(s, _CurrentText, System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreWidth | System.Globalization.CompareOptions.IgnoreCase)) { flg = true; } break; } if (flg) { listBox.Items.Add(s); flg = false; flg1 = true; } } } } if (flg1) { listBox.SelectedIndex = 0; if (_CurrentText == listBox.SelectedItem.ToString()) { listBox.Items.Clear(); return(false); } return(true); } else { return(false); } }
public static int IndexOfIgnoreCase(string source, string value) { return(compare_info.IndexOf(source, value, System.Globalization.CompareOptions.IgnoreCase | System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreWidth)); }