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 /
  • Help Room /
avatar image
0
Question by Rin · Mar 03, 2016 at 05:52 AM · arraystrings

String array out of index C#

I am currently writing a little program that takes a string of numbers, splits them into lines and then writes them to a file. The problem is however all of my string arrays work just fine except this one and I cannot figure out why. The code is bellow and like I said I don't get why sysid is failing since sysidpart works just fine.

 string[] sysid;
 string[] sysidpart;
 sysid = new string[10];
 sysidpart = new string[sysintcount];
 while (H < sysintcount)
 {
     sysidpart[H] = syscode.Substring((H * 4), 4);
     if (I == 0)
     {
         sysid[J] = sysidpart[H];
         H++;
         I++;
     }
     else if (I <= 3)
     {
         sysid[J] = sysid[J] + "-" + sysidpart[H];
         H++;
         I++;
     }
     else if (I == 4)
     {
         J++;
         I = 0;
     }
 }

Comment
Add comment · Show 4
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 Eno-Khaon · Mar 03, 2016 at 06:42 AM 0
Share

I'm assu$$anonymous$$g that "J" is declared at a value of 0 somewhere...

Aside from that, does "sysintcount" ever reach a value greater than ~50? If so, your hard-coded string size of 10 for sysid would be exceeded.

avatar image Rin Eno-Khaon · Mar 03, 2016 at 07:44 AM 0
Share

J is declared earlier as 0 it is a counter for each one. As for sysintcount it can reach over 50 but unlikely I believe with the current settings it stops at 42.

What I am trying to do is take sysidpart[] and put them into lines of 4 (so sysidpart[1,2,3,4] are a line) and then store that line in sysid[]. This is mainly to clear it up in the text file so it looks more organized.

avatar image rajavamsidhar_gvs · Mar 03, 2016 at 07:41 AM 0
Share

if you are starting your array from 0 (zero) then in less than condition dont take equals-to. may be it may give solution.

avatar image Rin rajavamsidhar_gvs · Mar 03, 2016 at 09:57 PM 0
Share

That is why I store the array counter on a seperate int like I, I do it to run these and like I mentioned I have similar things in this same script that all work fine but this one is giving my issues for some reason.

1 Reply

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

Answer by Rin · Mar 03, 2016 at 10:16 PM

I figured out the issue, I put some print commands in the loop to see how it would turn out and it seemed that it was not having the error on the first loop but on a later one so I added in an extra zero to sysid and it works perfectly. Thank you for the help guys seems the error was on my end.

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

39 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

Related Questions

Pull int from string if within square brackets 1 Answer

C# Comparing a String to an Array? 1 Answer

Is it possible to have 2 references in an array? 1 Answer

Cannot convert 'String' to 'Array'. 2 Answers

Remove empty "" strings from array String[] 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