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
2
Question by user-9438 (yahoo) · Feb 19, 2011 at 02:47 PM · variablestringintconvert

Converting a single String character to representative int. How? Javascript

Say I have the letter "A" in a string variable.

And I want to perform "addition" upon it, so that it becomes "B", then "C", and then later I want to go backwards, from "C" to "B", and "B" to "C".

I've seen somewhere that this can be represented numerically, by a number between 0 and 255, but don't know what this numerical representation of the alphabet is called. Or how to change the string to this format for addition, and then back to a string for printing.

The question, how do I turn that variable string of the letter "A" into that representative number, add 1 to that number, and then pass it back to the string variable as the new number, thereby increasing the "A" to "B".

Or is there are a better way to do this?

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
1

Answer by Molix · Feb 19, 2011 at 03:30 PM

It sounds like you want the hexadecimal equivalent of "A". Hexadecimal is base-16, and uses the digits 0-9 then A-F.

Here's an example of converting hex and back in C#.

Edit, on re-reading, I'm thinking you might just want the character code version of "A". In that case, you can just do:

string str = "A";
char c = str[0];
Debug.Log( c );  // prints A
c++;
Debug.Log( c );  // prints B

Edit, added JS:

var str : String = "A";
var c : int = str[0];
Debug.Log( System.Convert.ToChar( c ) );  // prints A
c++;
Debug.Log( System.Convert.ToChar( c ) );  // prints B
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 user-9438 (yahoo) · Feb 19, 2011 at 03:41 PM 0
Share

is this much the same in UnityScript (javascript)?

I can't find much on char in the unity reference that makes any sense to me.

avatar image jahroy · May 16, 2011 at 05:52 PM 0
Share

I don't think there is a char class for UnityScript. I'm assu$$anonymous$$g that's why you have to use String.Split(","[0]) to split a string by commas

avatar image
1

Answer by jahroy · May 16, 2011 at 05:57 PM

The integer value of a character is referred to as its ASCII value.

A is 65, B is 66, C is 67, etc...

I'm not sure if everything is the same in unicode.

var stringValue : String = "A";

/ get the int value of the first character in the string /

var intValue : int = stringValue[0];

print(intValue);

intValue ++;

var stringFromAscii : String = System.Convert.ToChar(intValue);

print(stringFromAscii);

Comment
Add comment · 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

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

Array - Convert Object into Int 5 Answers

[SOLVED] Convert this line from string to int 1 Answer

I can't print a int.ToString() variable in a guiText.text 1 Answer

GUI.Label shows volume from a slider 3 Answers

Converting a string to an int 2 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