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 justking14 · Oct 28, 2014 at 10:34 AM · instantiatetextsplitregex

Loading a text document without spaces

For my project I need to load a very large document. The document does not have spaces between the characters, but it does have many lines. My problem comes from the line: lines = Regex.Split(text, string.Empty); This only seperates the characters by lines leading to a single long row of objects instead of a maze. How do I fix this?

  string text = System.IO.File.ReadAllText("map.txt");
     string[] lines = Regex.Split(text, string.Empty);
     int rows = lines.Length;
     string[][] levelBase = new string[rows][];
     for (int i = 0; i < lines.Length; i++)  {
         string[] stringsOfLine = Regex.Split(lines[i], " ");
         levelBase[i] = stringsOfLine;
     }
     string[][] jagged =  levelBase;
     

     for (int y = 0; y < jagged.Length; y++) {
         for (int x = 0; x < jagged[0].Length; x++) {

             Debug.Log(jagged[0].Length );
             switch (jagged[y][x]){
             case sfloor_valid:
                 Instantiate(floor_valid, new Vector3(x, -.2f, -y), Quaternion.identity);
                 break;
             case sfloor_obstacle:
                 Instantiate(floor_obstacle, new Vector3(x, 0, -y), Quaternion.identity);
                 break;
             case sfloor_oob:
                 Instantiate(floor_OutOfBounds, new Vector3(x, 0, -y), Quaternion.identity);
                 break;

             }
         }
     }       
 }
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 justking14 · Oct 28, 2014 at 12:22 AM 0
Share

I have, but found nothing that dealt with both a lack of spaces btw characters and more than a single line

avatar image gjf · Oct 28, 2014 at 10:36 AM 0
Share

is there some ter$$anonymous$$ator at the end of each line within this 'very large' document? (how large is very large?)

splitting the text with String.Empty ins$$anonymous$$d of that ter$$anonymous$$ator character is never going to work...

avatar image justking14 · Oct 31, 2014 at 11:42 PM 0
Share

height 209 width 281

avatar image justking14 · Nov 01, 2014 at 12:40 AM 0
Share

no ter$$anonymous$$ator at the end and not allowed to edit the document

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Nov 01, 2014 at 02:07 AM

I think you are going about this the hard way. You can do:

  string text = System.IO.File.ReadAllText("map.txt");
  string[] lines = lines = text.Split (new[] { '\r', '\n' }, System.StringSplitOptions.RemoveEmptyEntries);

As with your code above, you have an array of strings. I use this particular split methods since the result will work for both Mac/Unix and Windows line endings, and produce an array without any empty lines. You can access any specific character just like the jagged array you are trying to produce. For example, you can do:

 Debug.Log(lines[2][2]);

...which will display the third character in the third line. If you really want a jagged character array, you can process 'lines' array produced in the previous step as follows:

 char[][] data;
 data = new char[lines.Length][];
 for (int i = 0; i < lines.Length; i++) {
      data[i] = lines[i].ToCharArray();
 }



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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to save script component variables at runtime from IOS device? 1 Answer

How to instantiate prefab over the text one letter at a time? OR how to get transform of letters in a text 0 Answers

Help making a damage number system 1 Answer

Change The GuiText.text by code 1 Answer

split object when player touches anywhere in the screen 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