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 Alismuffin · May 20, 2012 at 04:29 AM · c#listapiconverting

Removing certain characters from strings and converting to a list

Hello!

I am sending query data from Unity3D to an external API. The API is taking my query, generating a result and sending it back.

However when it sends back certain values, it sends them back like this:

["c7385f31-2c3e-42ae-aae2-57c5ea66088f", "e6f8f4db-76c4-43a9-b5d3-5d3be606cabd", "22a55fa7-bf1f-46d9-9c1e-67336c4f55c4"]

That is a list of id codes sent from the API to me. However it is all one continuous string.

How would I go about converting this into a list?

I figure what I need to do is remove firstly the ['s and then seperate each one from each other. I'm not too sure how to go about it and have searched the internet for a solution but haven't found one.

(I am using C# btw, and heard that lists were better than arrays for this particular thing. Please do correct me if I'm wrong!)

Thanks!!

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
Best Answer

Answer by Berenger · May 20, 2012 at 05:04 AM

So, you receive "c7385f31-2c3e-42ae-aae2-57c5ea66088fe6f8f4db-76c4-43a9-b5d3-5d3be606cabd22a55fa7-bf1f-46d9-9c1e-67336c4f55c4" and you want to split it up in three and store each parts in a list am I right ?

I guess there isn't a character of separation then, but each part seems to have the same number of chars (I didn't count). You should use SubString and add each result to a List

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 Alismuffin · May 20, 2012 at 05:11 AM 0
Share

I receive it exactly how I wrote it up there, brackets and commas and all.

Yes I think they are the same length (It would certainly make the job easier if they were!

I'm looking around for ways of getting rid of the ['s , and ,'s right now so that I will receive the result you posted

Thanks for the SubString Idea! Ill check it out :)

Thanks man!

avatar image Alismuffin · May 20, 2012 at 05:15 AM 0
Share

Substring is perfect for what I needed! No need to individually cut any unwanted symbols out either! $$anonymous$$uch $$anonymous$$udos to you :)

EDIT: And just in case you're curious, each string is 346 chars long

avatar image
2

Answer by Eric5h5 · May 20, 2012 at 05:42 AM

Just use String.Split, in combination with Substring to strip the outer characters. Then it doesn't matter if the lengths are the same or not. You don't need a List; an array is fine, which is what Split returns.

 string input = "[\"c7385f31-2c3e-42ae-aae2-57c5ea66088f\", \"e6f8f4db-76c4-43a9-b5d3-5d3be606cabd\", \"22a55fa7-bf1f-46d9-9c1e-67336c4f55c4\"]";
 string[] splitter = {"\", \""};
 string[] idCodes = input.Substring(2, input.Length-4).Split(splitter, System.StringSplitOptions.None);
 
 foreach (var id in idCodes) {
     Debug.Log (id);
 }
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 Alismuffin · May 20, 2012 at 05:51 AM 0
Share

Thanks man! That certainly is an efficient way of doing it. $$anonymous$$uch appreciated!

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

6 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Make Lists within a List 0 Answers

Confused about copying Lists! 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