0
searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));

if I have for example: Guid it will find it only I start typing with G...Gui but if I will type gui....it will not find it. and if I type only g it will find other results with lower cases of g.

but I want both upper and lower case when searching.

string searchString;
    void OnGUI()
    {
        GUI.color = Color.white;

        GUILayout.FlexibleSpace();
        searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));
        if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
        {
            searchString = "";
            GUI.FocusControl(null);
        }

        scrollPos =
            EditorGUILayout.BeginScrollView(scrollPos, false,true,
            GUILayout.ExpandWidth(true), GUILayout.Height(position.height));

        foreach (KeyValuePair<GameObject, string> pair in dictio)
        {
            EditorGUILayout.BeginHorizontal();

            if (searchString != null)
            {
                if (pair.Value.Contains(searchString))
                {
                    EditorGUILayout.ObjectField(pair.Key, typeof(GameObject), true);
                    num.Add(EditorGUILayout.TextField(pair.Value).Length);
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        GUILayout.EndScrollView();
    }
  • 1
    Following your past questions a bit it sounds like you are basically r-implementing something like a custom [`ObjectSelectorSearch`](https://docs.unity3d.com/ScriptReference/SearchService.ObjectSelectorSearch.html) .. which btw uses `StringComparison.InvariantCultureIgnoreCase` – derHugo May 03 '23 at 06:24
  • 1
    In general before opening a lot of new questions please [do some research first](https://www.google.com/search?q=c%23+string+ignore+case+site:stackoverflow.com) .. this has been asked and answered a good ton of times already – derHugo May 03 '23 at 06:28

2 Answers2

0

Solution is to add:

StringComparison.CurrentCultureIgnoreCase

the code:

string searchString;
    void OnGUI()
    {
        GUI.color = Color.white;

        GUILayout.FlexibleSpace();
        searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));
        if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
        {
            searchString = "";
            GUI.FocusControl(null);
        }

        scrollPos =
            EditorGUILayout.BeginScrollView(scrollPos, false,true,
            GUILayout.ExpandWidth(true), GUILayout.Height(position.height));

        foreach (KeyValuePair<GameObject, string> pair in dictio)
        {
            EditorGUILayout.BeginHorizontal();

            if (searchString != null)
            {
                if (pair.Value.Contains(searchString, StringComparison.CurrentCultureIgnoreCase))
                {
                    EditorGUILayout.ObjectField(pair.Key, typeof(GameObject), true);
                    num.Add(EditorGUILayout.TextField(pair.Value).Length);
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        GUILayout.EndScrollView();
    }
0

You can specify you don't care about case in your string contains function

if (searchString != null)
{
    if (pair.Value.Contains(searchString, StringComparison.CurrentCultureIgnoreCase))
    {
        EditorGUILayout.ObjectField(pair.Key, typeof(GameObject), true);
        num.Add(EditorGUILayout.TextField(pair.Value).Length);
    }
}
Jay
  • 2,553
  • 3
  • 17
  • 37