//from the internets: internal static int GetWidth(Text Text){ //Make sure its not empty, because this would crash it later otherwise. if( Text.ToString().Length == 0 ) return 0; //Temp variables that use the same font and size as the original text. //This is to get the width of one '#' Text Temp1 = new Text( "#", Text.Font, Text.CharacterSize ); Text Temp2 = new Text( "# #", Text.Font, Text.CharacterSize ); //Now we can get the width of the whitespace by subtracting the width of 2 '#' from "# #". int Width = (int)(Temp2.GetGlobalBounds().Width - Temp1.GetGlobalBounds().Width*2); //The width of the string without taking into consideration for spaces left at the beggining or end. int TotalWidth = (int)Text.GetGlobalBounds().Width; //Get the text from the sf::Text as an std::string. string str = Text.ToString(); //Bool to see if we encounter a string consisting of only spaces. bool OnlySpaces = false; //Go through all characters in the string from the start. for( int i = 0; i < str.Length; i++ ) { if( str[i] == ' ' ) //Add each space's width to the sum of it all. TotalWidth += Width; else break; //Check if we have gone through the whole string. if( i == str.Length -1 ) OnlySpaces = true; } //Go through all characters in the string from the end, as long as it wasn't only spaces. if( !OnlySpaces ) { for (int i = str.Length - 1; i > 0; i--) { if (str[i] == ' ') //Add each space's width to the sum of it all. TotalWidth += Width; else break; } } return TotalWidth; }