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 AnnaLadySG · Mar 03, 2015 at 01:29 PM · textstringsystem.iounicode

Write a Unicode escape character code to a text file

I've got C# script that converts a text file with all the game narrative in from the writer and converts it into a string file that can be used in the game. I need to put the Unicode escape characters into the string file by their Unicode codes - so, I need to swap all apostrophes for \u0027 and so on. The text file written out however swaps the Unicode codes back to the character I'm trying to replace - so:

 string cleanString = dirtyString.Replace("'","\u0027");

Results in the word "There's" being written out as "There's", rather than "There\u0027s".

To test I tried putting in another word instead of a code and that worked fine -

  string cleanString = dirtyString.Replace("'","TEST");

Results in "ThereTESTs" so I'm thinking that its the Write process that's swapping the code back to the character. I'm using SystemIO File.WriteAllText to write the text file.

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 meat5000 ♦ · Mar 03, 2015 at 01:29 PM 0
Share

I don't know if I'm right here, but the problem could be that you are presenting it as a string rather than a character.

https://msdn.microsoft.com/en-us/library/aa664669%28v=vs.71%29.aspx

http://stackoverflow.com/questions/9738282/replace-unicode-escape-sequences-in-a-string

Looking at maccabbe's answer, I think I misread.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by maccabbe · Mar 03, 2015 at 01:38 PM

This is because "'" == "\u0027". If you want "\u0027" to show up in your text file, you have to escape the escape sequence, i.e.

 string cleanString = dirtyString.Replace("'","\\u0027");
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 AnnaLadySG · Mar 04, 2015 at 01:54 PM 0
Share

Cool - That results in \\u0027 in the string file ins$$anonymous$$d of the apostrophes. I'm not sure if this is now going to work to create an apostrophe when it is read in as a string file - I'll give it a whirl and see what happens. Ta!

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

Finding a character unicode in C# 0 Answers

Read dialog text from text file in javascript 0 Answers

Set string.ToCharArray() to the first letter 1 Answer

X.Text just uses random values 1 Answer

Changing a text equal to a string variable 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