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 /
  • Help Room /
avatar image
1
Question by Kreekakon · Oct 20, 2015 at 07:05 PM · c#arraystring

How to see if a string in a string array is equal to a normal string in C#?

Hello all! I have an issue right now. Currently I have a function which will check to see if an array in a string is equal to one that I input into the function. However I have found out that something which stops the script from working properly is that a normal string seemingly cannot be equal to a string from a string array even if they are equal on sight (I have tested this via debug.log).

My question is how I can compare these two or convert one of them to allow proper comparison.

Here is my main script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class dialogue : MonoBehaviour
 {
     public TextAsset dialogueFile; //The .txt file the script draws its dialogue lines from
 
     public string[] lineTitle; //the array that holds the titles of the dialogue line
     public string[] line;//the array that holds the actual contents of the dialogue line 
     public    GameObject sub;//The on-screen text object used to display the dialogue line
     private float timeHolder; // holds the countdown duration
     private bool timeOut = true; //Determines if time has run out for the subtitle's appearance yet. If this is false, the subtitle line will be deactivated
 
     void Start ()
     {
         sub.SetActive (false);
     }
     
     // Update is called once per frame
     void Update ()
     {
         //Starts Counting down 
         if (timeOut == false) {
             timeHolder -= Time.deltaTime;
             if (timeHolder < 0) {
                 sub.SetActive (false);
                 timeOut = true;
             }
         }
     }
 
     public void displayLine (string lineName, float duration)
     {
         string[] lines = dialogueFile.text.Split ('\n'); //Creates a string array from the .txt file
 
         timeHolder = duration;
 
         for (int g = 0; g<3; g++) {
             lineTitle [g] = lines [g * 3]; //puts line title in appropriate string array slot
             line [g] = lines [1+ (g * 3)]; //puts actual line in appropriate string array slot
 
             if (lineName==lineTitle [g]) { //The MAIN part which does not work. Should be comparing the line title to the line I input in a function. Displays the subtitle if this is true
                 sub.SetActive (true);
                 Debug.Log(lineTitle [g]);
                 sub.GetComponent<UnityEngine.UI.Text> ().text = line [g];
                 timeOut = false;
             }
         }
     }
 }

Here is what an example of the main "displayLine" function from the previous script being used:

 displayLine("testLine1",3);

Here is what the .txt file that I draw the dialogue lines from looks like (Placeholder lines):

 testLine1
 I am going to try and decide what to do
 //////////////////////////////
 testLine2
 Maybe this will work just fine?
 //////////////////////////////
 testLine3
 How about we try being certain about it?
 //////////////////////////////
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by vintar · Oct 20, 2015 at 07:19 PM

You could use lineName.Equals(lineTitle[g]) I think. check here : link text

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 Kreekakon · Oct 20, 2015 at 07:27 PM 0
Share

I've already tried the Equals method, and did it again after you suggested it here. It still returns false like usual.

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

33 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

Related Questions

trying to get an Array string to read an Int 0 Answers

Storing input to array 1 Answer

Error CS1061: Are you missing an assembly reference? 2 Answers

How to make a random string from array in C#? 1 Answer

Is it possible to have 2 references in an array? 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