Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Mattivc · Mar 04, 2010 at 06:53 PM · variablestringjavascript-specific

Finding the length of a string

How can i find out the character length of a string variable and then store that value in a integer variable, using javascript?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Eric5h5 · Mar 04, 2010 at 07:03 PM

var someString = "blah blah";
var stringLength = someString.Length;
Comment
Add comment · Show 1 · 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 dissidently · Dec 22, 2010 at 07:54 AM 0
Share

Hey Eric thankyou for this. the first answer was a little confusing because of the use of "str". Your answer is much less confusing for me, a lone wonderer through the answers of Unity.Answers

avatar image
3
Best Answer

Answer by Ashkan_gc · Mar 04, 2010 at 08:33 PM

you should use the Length property the string class.

var l = str.Length;

it will return an int so the variable in lefthandside will become an int because js is a dynamic language. infact the string class in so powerful but unity guys did not document it. take a look at the real documentation of hte class here. String is not a unity class and is the System.String class of .NET/MONO. see the Length property too.

Comment
Add comment · Show 3 · 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 Eric5h5 · Mar 04, 2010 at 08:49 PM 2
Share

The left hand variable doesn't become an int because JS is a dynamic language, it becomes an int because of type inference. C# 3.0 does the same thing. (In fact, JS in Unity is primarily statically-typed, and becomes completely so if you use #pragma strict).

avatar image Ashkan_gc · Mar 04, 2010 at 09:28 PM 0
Share

oops you are right because i defined the variable here. you are wrong in the other side. the js language of unity is a dynamic language and it will become strictly typed if you use pragma strict. var keyword in C# 3 is different and there is no dynamic feature outthere. you just say the compiler that i will define the type of this variable the frst time that i assign something to it. you can not change it later by any means. in C# 4 you can use dynamic keyword to use new dynamic features of C# language.

avatar image Eric5h5 · Mar 04, 2010 at 10:43 PM 2
Share

No, I am not wrong. JS is statically typed when you use statements like "var l = str.Length;", because of type inference. You cannot change the type of the "l" variable later; it will always be an int. This is the same type inference that C# 3.0 has. JS only uses dynamic typing when the compiler can't figure out the type. Feel free to ask the Unity $$anonymous$$m if I'm right. ;)

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

No one has followed this question yet.

Related Questions

Getting variable name from a string 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Edit Variables From Game! 1 Answer

GameObject.name to string 2 Answers

Access a static var from different named scripts? 1 Answer


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