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 /
This question was closed Aug 26, 2017 at 03:57 PM by CAS_Kicks for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by CAS_Kicks · Aug 24, 2017 at 06:27 AM · stringreplaceregex

Replace() with string and Regex not replacing numbers/integers

Hey, there! I have a bunch of variables that I need to change to different names.

Currently they're ordered and stored in a scriptable object 'data' and held in my character objects as vars[].

I'm replacing all of the .cs file instances of vars[i] with the name held in data[i].

My code abstract is...

foreach(string assetPath in AssetDatabase.GetAllAssetPaths())

for(int v = 0; v < data.Count; v++)

string findText = "vars[" + i.tostring + "]";

string replaceText = data[i].name;

string finalFile = File.ReadAllText(assetPath);

finalFile = finalFile.Replace(findText, replaceText);

File.WriteAllText(finalFile)

It finds all the instances of vars[i] in each file perfectly fine (the actual code finds all instances of vars[i] in the file first), but when I try to replace them with string.Replace or Regex.Replace it doesn't work. When I change replace text to something without numbers it seems to work. What am I doing wrong?

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

  • Sort: 
avatar image
0
Best Answer

Answer by CAS_Kicks · Aug 26, 2017 at 03:57 PM

Turns out it was my fault. I went over the code tons of times before posting this, but the way my loops were nested things weren't being saved and re-read properly. Anyways... Nothing to see here.

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
avatar image
0

Answer by tanoshimi · Aug 24, 2017 at 06:37 AM

Do you really need to do this in Unity? I'd always do any Find and Replace operations through an IDE - it's trivial to do a Regex operation on all the files in a directory using Visual Studio, for example.

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 CAS_Kicks · Aug 24, 2017 at 06:47 AM 0
Share

I'm open to anything. What would that look like? I wasn't sure how I could do it while iterating through an array of variables (400+ in this case)

Follow this Question

Answers Answers and Comments

67 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

Related Questions

Replace chars in String with a Dictionary and avoid order-sensitive problems 0 Answers

SOLVED - String replace % with " in C# 1 Answer

SOLVED Exclude set of keywords from string (using Regex) 1 Answer

Trying to Create Custom Encryption 1 Answer

String - Replace Letters With Numbers 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