- Home /
Question by
Anxo · Feb 28, 2012 at 01:26 AM ·
javascriptstring
Character at index of string? Finding which character is at an index like in Javascript charAt
I am trying to find the Character of an index of a string. The reason I am doing this is because I would like to break up a string. lets say every 5th space.. " " I would like to replace with a break. Because I can not find a width and text wrap with a text mesh.
Any ideas? I have been looking at this http://www.w3schools.com/jsref/jsref_charat.asp
ans so I have started to write something like this to test if it would insert the * private var myComment : TextMesh;
function Awake(){
myComment= GetComponent(TextMesh);
}
function Start(){
AssignComment("This is some cool text because it is very long and I love it. you love it? yes you love it , its just great to have such a long commnet. ");
}
function AssignComment(incComment : String){
var SeperatedString : String = incComment;
var CommentLength : int = incComment.length;
for(var i : int = 0; i< CommentLength; i+=20)
for(var b : int = 0; b<20; b++)
if(incComment.charAt(i+b)==" ")
{
SeperatedString.Replace(SeperatedString.charAt(i+b),"*");
b=20;
}
myComment.text = SeperatedString;
}
Comment
Answer by Eric5h5 · Feb 28, 2012 at 01:37 AM
A string is an array of chars.
if (incComment[i+b] == " "[0])
That's how you refer to chars in Unityscript. There's no other way besides referring to entries in string arrays, so " "[0]
is the first (and only) entry in the string array consisting of a space.