- Home /
GUI set max amount of characters for Label
I have a GUI system and it displays strings from different parameters, but I wanna add a max size for each string, so that for example when the string exceeds a certain amount of characters, it ends in "..." at that point where it crosses the max (for example). Is that possible? Here is the code I am using...thank you in advance!
 void OnGUI()
     {
     int row = 0;
     int rowHeight = 30;
     foreach (KillFeedInfo k in KFI)
             {    
             GUI.Label(new Rect(Screen.width - 300, 0 + row * rowHeight, 200, 200), k.Killer);
             GUI.Label(new Rect(Screen.width - 200, 0 + row * rowHeight, 200, 200), "[" + k.Gun + "]");
             GUI.Label(new Rect(Screen.width - 100, 0 + row * rowHeight, 200, 200), k.Killed);
             row++;
             }
     }
Answer by zombience · Oct 18, 2013 at 05:04 PM
This works for display purposes:
 int strlen = 8;
 string displayString = "a big long text string that you want to truncate";
 displayString = displayString.Remove(strlen);
 displayString += "...";
 Debug.Log(displayString);
if you want to preserve the original string, then make a duplicate variable and pass the original into it and display that.
 foreach ($$anonymous$$illFeedInfo k in $$anonymous$$FI)
             {    
             k.$$anonymous$$iller.Remove(maxString);
             k.$$anonymous$$illed.Remove(maxString);
             k.$$anonymous$$iller = k.$$anonymous$$iller += "...";
             k.$$anonymous$$illed = k.$$anonymous$$illed += "...";
             GUI.Label(new Rect(Screen.width - 300, 0 + row * rowHeight, 200, 200), k.$$anonymous$$iller);
             GUI.Label(new Rect(Screen.width - 200, 0 + row * rowHeight, 200, 200), "[" + k.Gun + "]");
             GUI.Label(new Rect(Screen.width - 100, 0 + row * rowHeight, 200, 200), k.$$anonymous$$illed);
             row++;
             }
do you mean to apply it like this? Im a bit confused.
Your answer
 
 
             Follow this Question
Related Questions
Decreasing Length of a String? 2 Answers
Using Polish characters in OnGUI 1 Answer
How do I get a list to randomly select.... 1 Answer
How to access var in other class using string 0 Answers
Fade out GUILayout Area? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                