Search Unity

Textarea problem ... please help

Discussion in 'Immediate Mode GUI (IMGUI)' started by hedfyy, Feb 28, 2018.

  1. hedfyy

    hedfyy

    Joined:
    Jan 22, 2018
    Posts:
    1
    i created an textarea using
    Code (CSharp):
    1. stringToedit= GUI.TextArea (new Rect (5, 5, 350, 200), stringToedit);
    but when i want to change for example stringToedit[2] ="a";

    i get this error:
    Property or indexer string.this[int] cannot be assigned to (it is read-only)

    i also tried the declaration with get and set but didn't work :/

    so i wanna first show an TextArea and then i wanna get this string to edit it
    for exampe :

    Code (CSharp):
    1. myString= GUI.TextArea (new Rect (5, 5, 350, 200), myString);
    2. for(int i=0 ; i < myString.Length ; i++ ) {
    3. if ( myString[i] ==" "){
    4. myString[i] = "a";
    5. }
    6. }
    7.  
    so i get the string then i'll test if there an blank space to replace it with "a"

    i also tried the string methods but not working :/


    ho to do that please :)
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    This is not a limitation of the textarea or anything, it is not allowed to set string values through the char array like that. What I recommend doing is this:
    Code (CSharp):
    1. myString = myString.Replace(' ', 'a');
    This replaces all space chracters with an a character. btw ' is for characters, " is for strings.