Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

String problem

Discussion in 'Scripting' started by ache, Oct 14, 2014.

  1. ache

    ache

    Joined:
    Oct 13, 2014
    Posts:
    9
    How to write the text like "T e x t" instead of "Text" with Gui.Label ?
     
  2. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    You could try:
    GUI.Label... ("T " + "E " + "X " + "T ");

    I do not know why "T e x t" would not work to write for you...
     
  3. ache

    ache

    Joined:
    Oct 13, 2014
    Posts:
    9
    I asked my question simple. Actually in my project i have a random list in this list has 5 questions and has their answers. (One question has one answer and player must the use GUI.TextField to know question's answer) I can write this question's answers on main camera with the use (answer.tex += "?"). But i want to use GUI.DrawTexture instead of ?. I tried every methods but i failed. If i make the string like "A N S W E R" my problem will gone. My label is GUI.Label(new Rect (10.0f, 100.0f, 800.0f, 75.0f), answerText); How can write the answerText on main camera like "? ? ? ?" not like "????"
     
  4. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    Having plus and space in the "" signs should help. If it does not, I'm sorry :/
     
  5. ache

    ache

    Joined:
    Oct 13, 2014
    Posts:
    9
    No, it doesnt :) No problem bro thanks for try to help
     
    Sykoo likes this.
  6. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    You could try using this: http://www.dotnetperls.com/insert to go through your string an insert a space after every letter
    But i don't see why you don't just put spaces in your string?
     
  7. ache

    ache

    Joined:
    Oct 13, 2014
    Posts:
    9
    Gui.Label doesn't recognize the space. I puted the space in my string (not to random list) but it doesnt happen. I have two choices;
    1 - If i can put the a image instead of "?" then my problem to be solved.
    2 - If i can change the string character space on GUI.label then my problem to be solved.
    I've been trying for 6 days but i could not.
     
  8. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    GUI.Label will recognize the space i have tried this line its working

    Code (csharp):
    1.   GUI.Label(new Rect(100,100,100,30), "T"+" e"+" x"+" t");
     
  9. ache

    ache

    Joined:
    Oct 13, 2014
    Posts:
    9
    schetty : How can i print the string like this way ?
     
  10. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    489
    You guys aren't understanding. He wants to take a string like "myString" and run it through a function to get "m y S t r i n g". Kind of like this ;)
    Code (CSharp):
    1. void SpaceString(string stringToSpace){
    2. string newString = "";
    3. for(int i = 0; i < stringToSpace.Length; i++){
    4. newString += stringToSpace[i] + " ";
    5. }
    6. return newString;
    7. }
    Then you can just say
    GUI.Label(new Rect(0,0,512,256),SpaceString("Answer"));

    Hope I helped :)
     
  11. ache

    ache

    Joined:
    Oct 13, 2014
    Posts:
    9
    Unfortunately no :( I downloaded the NGUI and i dont make with it too..
     
  12. parandham03

    parandham03

    Joined:
    May 2, 2012
    Posts:
    174
    Try below code it works fine
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Linq;
    4.  
    5. public class SpaceGenTest : MonoBehaviour {
    6.  
    7.     string withoutSpaces="Text";
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.      
    12.         var withSpaces = withoutSpaces.Aggregate(string.Empty, (a, i) => a + i +' ');
    13.         print(withSpaces);
    14.  
    15.     }
    16.  
    17. }
    18.  
     
    ZO5KmUG6R likes this.