Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Ayuda sustituir texto por otro

Iniciado por daniele_kiro, Junio 24, 2018, 01:20:41 PM

Tema anterior - Siguiente tema
Junio 24, 2018, 01:20:41 PM Ultima modificación: Junio 25, 2018, 07:54:49 AM por pioj
Hola buenos dias, tengo la siguiente duda.
 
He intentado encontrar algo en internet pero no doy con lo que realmente intento hacer...
 
Tengo lo siguiente:
 



   
       
   
   
      var Player = "Juanito"
   
   
      var x = "2"
   
   
      Texto = (Player) recogio (x) botella de vida.
   
   
      Texto = El atacante recibe (x) daño de (Player).
   
   
       
   

[/quote]
 
Quiero sustituir la palabra (Player)  y la (x) por las variable mediante script.
 
Alguna forma que yo escriba el texto y poder detectar la palabra (Player) y (x) y sustituirla...
 
 
 
No se si se entiende o me he explicado mal... 
 
Un saludo y gracias de antemano!
 
 

Hola, podés sumar strings y hacer algo así:
 

//valores iniciales por ej
string player = "Juanito";
string x = "2";
...
//cuando prepares o presentes las strings de la forma que quieras
string Texto1 = player + "recogio " + x + " botella de vida." ;
string Texto2 = "El atacante recibe " + x + " daño de " + player + ".";

 
 


Junio 24, 2018, 06:53:49 PM #3 Ultima modificación: Junio 25, 2018, 07:55:18 AM por pioj
también puedes utilizar string.replace(). 
 



   
       
   
   
      Texto = El atacante recibe (x) daño de (Player).
   
   
      Texto.replace("x", x).replace("Player", player);
   
   
       
   

[/quote]
 
 

yo en JAVA utilizo el StringBuilder al hacer overrider del toString, en c# también existe pero desconozco si es mas eficiente que string.format()

 
 
Cita de: Kvashir date=1533157108yo en JAVA utilizo el StringBuilder al hacer overrider del toString, en c# también existe pero desconozco si es mas eficiente que string.format()
   


No. StringBuilder es actualmente el método más rápido y eficiente para trabajar con strings en Unity3D.

Etiquetas: