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 /
avatar image
0
Question by Prefab · May 12, 2016 at 04:41 AM · c#stringstring.splitstring comparison

How to extract part of a string variable?

I have a string variable in C# in the follow format:

part1/part2/variable1/variable2/variable3

The "parts" of the string are always the same, however the "variables" change and so I have no way of knowing in advance what they will be. What I need is to be able to extract "variable1" only and store this in another string variable. I have tried using string split and trim, but because I don't know how many characters long any of the "variables" will be, I'm not sure how far after the end of "part2" I should ignore/remove the rest of the string.

Any suggestions how to do this?

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 saud_ahmed020 · May 12, 2016 at 05:19 AM 0
Share

@Prefab Just concatenate a character which will not be part of your string variable. e.g

Part1/part2/"$XYZ$/ABC/"

Note: "$XYZ$" is vairable1and "ABC" is variable3.

I hope you got my idea.

avatar image Prefab saud_ahmed020 · May 12, 2016 at 05:35 AM 0
Share

Sorry not sure I understand. How can I concatenate if I don't know what variable1 will be?

avatar image daleth90 · May 12, 2016 at 05:36 AM 0
Share

string.Split( '/' ) doesn't work? I think it doesn't need the length of characters.

avatar image Prefab daleth90 · May 12, 2016 at 06:05 AM 0
Share

Do you mean splitting the string into an array of strings and then making the 3rd array item equal to variable1? Trying this now...

1 Reply

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

Answer by 5c4r3cr0w · May 12, 2016 at 06:05 AM

String.Split() returns the array of the string so If you use String.Split("/") , it'll split the entire string into seaprate strings before and after the character "/".

For example you have string "Variable1/Variable2". if you use "Variable1/Variable2".Split("/"), you'll have two different string "Variable1" and "Variable2" but you have to store it in array of the string like

 string[] x = "Variable1/Variable2".split('/');

So you'll have x[0] = "Variable1" and x[1] = "Variable2";.

Now in your case I don't see any need to know how long any string should be as you want to seaprately store the variable1. So Split() is the best option for you.

Hope it helped.

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 Prefab · May 12, 2016 at 06:31 AM 0
Share

Thanks a lot!!!

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

144 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 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

Distribute terrain in zones 3 Answers

String.Split Not Splitting Correctly. Some Duplicates are being deleted. 1 Answer

Grab part of a string by looking for keyword 2 Answers

Multiple Cars not working 1 Answer

Can i give GetComponent a variabel instead of a scriptname? 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