Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Eric5h5 · Feb 28, 2012 at 01:37 AM

A string is an array of chars.

 if (incComment[i+b] == " "[0])
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anxo · Feb 28, 2012 at 02:06 AM 0
Share

why did you ad the [0] at the end?

avatar image Eric5h5 · Feb 28, 2012 at 02:20 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Javascript - Calling a random String 2 Answers

String Problem in Java Script 1 Answer

Combo Script Problem 1 Answer

How to convert a float to a string and then have it appear in a gui rect 3 Answers

How you can start the animation of an object as finished another ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges