Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by FeeeshMeister · Sep 09, 2016 at 11:37 PM · arraykeyboardtostringchar

How do I convert a char array to string (C#)?

I have a problem. I am trying to create an on-screen keyboard, and right now I am just testing how to create a string from the characters the player inputs. Here is the code, using UnityEngine; using System.Collections; public class OnScreenKeyboard : MonoBehaviour { %|-2027507329_1|% %|134211281_2|% %|703842105_3|% %|1650434119_4|% %|-2095084726_5|% %|1016882716_6|% %|-415537406_7|% %|102902370_8|% %|2047609155_9|% Input[6] = 'W'; %|-270864002_11|% %|-1309702685_12|% %|-963489900_13|% %|-641054115_14|% %|-1870234116_15|% %|-1626960618_16|% } }

It should log the string HELLO WORLD, but it returns a nullreferenceexception.

NullReferenceException: Object reference not set to an instance of an object OnScreenKeyboard.Start () (at Assets/Resources/Script/OnScreenKeyboard.cs:7)

If anyone one can help, I would appreciate it.

Comment
Add comment · Show 3
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 FeeeshMeister · Sep 10, 2016 at 12:45 AM 0
Share

It seems that the code is not posting correctly, here it is

 using UnityEngine;
 using System.Collections;
 
 public class OnScreen$$anonymous$$eyboard : $$anonymous$$onoBehaviour
 {
     static char[] Input;
     void Start()
     {
         Input[0] = 'H';
         Input[1] = 'E';
         Input[2] = 'L';
         Input[3] = 'L';
         Input[4] = 'O';
         Input[5] = ' ';
         Input[6] = 'W';
         Input[7] = 'O';
         Input[8] = 'R';
         Input[10] = 'L';
         Input[11] = 'D';
         string Output = new string(Input);
         Debug.Log(Output);
     }
 }


avatar image Guppie1337 FeeeshMeister · Sep 10, 2016 at 01:34 AM 0
Share

That should work. Try using System;.

avatar image doublemax · Sep 10, 2016 at 12:21 PM 0
Share

You didn't initialize the size of the array.

Like Sergio7888 said, you missed one index.

And the array must be ter$$anonymous$$ated with a 0-byte.

1 Reply

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

Answer by Sergio7888 · Sep 10, 2016 at 06:52 AM

You skipped Input[9], so index 9 is null.
Try use System.Text.StringBuilder

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

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot print an array of char to the console. It prints system.char[] instead of the actual letters 2 Answers

Wher is the problem? My string isn't behaving... 1 Answer

Logic problem with lists C# 2 Answers

Array with pushing values? 0 Answers

Sound Effect Array plays all sounds when instructed to play one 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