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 ina · Apr 30, 2011 at 05:28 AM · javascriptarraystringsplit

split() for separators more than 1 characters

Is it possible to do a split() in Unity JS to turn a string to array, where the separator has more than one character, as in the below:

Apple<br />
Banana<br />
Canapple<br />
Comment
Add comment · Show 1
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 ina · Apr 30, 2011 at 05:30 AM 0
Share

this is related to my previous question, but the solution there only works for single character separators http://answers.unity3d.com/questions/33317/unity-js-equivalent-of-split

2 Replies

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

Answer by Eric5h5 · Apr 30, 2011 at 06:53 AM

The link that Mike provided in that other question shows the different options for String.Split. As you can see there, there's an option to use a string array instead of a char array, so you can provide a string array with one entry:

var test = "1a11abc2b22abc3c33";
var strings = test.Split(["abc"], System.StringSplitOptions.None);
for (s in strings) print (s);

There isn't a default for StringSplitOptions when you use a string array, so you have to provide something, such as None.

Comment
Add comment · Show 7 · 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 Cyborg · Nov 18, 2011 at 10:04 PM 0
Share

why in the world is it possible to use .net function in a javascript document? http://msdn.microsoft.com/en-us/library/system.string.split.aspx or am i wrong? this is currently turning my whole world upside down.

avatar image Eric5h5 · Nov 18, 2011 at 10:25 PM 1
Share

@Cyborg: Unity uses .NET for all script functionality. (Well, technically it's $$anonymous$$ono.) The language is irrelevant. "Javascript" in Unity is largely similar to JScript.NET anyway, it's not like web Javascript.

avatar image jahroy · Nov 18, 2011 at 11:02 PM 1
Share

You're going to enjoy your new upside down world. Just about anything you can find in the .Net documentation can be used in Unity's javascript. It's like cool and stuff...

avatar image jahroy · Nov 18, 2011 at 11:04 PM 0
Share

Wow... This answer is pretty awesome and is turning my world upside down. I wish I found it two days ago before I wrote my own string splitter (not that hard, really).

avatar image uni · Nov 18, 2011 at 11:50 PM 0
Share

I was trying to use this function yesterday but left out the System in the Split Options and it didn't work so I gave up(I'm a sap, huh, lol). Glad I saw this. I would also recommend to anyone using this for web data to consider tying together complex strings with WWW.EscapeURL(). That way only a single char is needed to split.

Show more comments
avatar image
-2

Answer by GlennHeckman · Apr 30, 2011 at 06:05 AM

Have you tried this:

var arr = str.Split("<br />"[0]); 
Debug.Log(arr[0]);

*Note, I'm pretty sure this will only work if the string actually contains the "<br />" characters.

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 Eric5h5 · Apr 30, 2011 at 06:54 AM 1
Share

That's a single char. "<br />"[0] will return " $(function () { setupComments($('#answer-container-61678'), true, false, croles, "full", true) }); $(document).ready(function () { var $answer = $("#answer-container-61678"); var $replyLink = $answer.find(".reply-link"); $replyLink.click(function (e) { e.preventDefault(); $answer.find(".add-comment-link").click(); }); });

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

JavaScript String Question 2 Answers

Converting a .CSV string array to a float array 1 Answer

Writing certain values of an array into a different array 3 Answers

Splitting String only on a "space". Using my method --- FIXED 2 Answers

convert string to list of 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