Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:33:17+00:00 2026-06-14T00:33:17+00:00

Why does this happen? I am getting a string from another class to compare

  • 0

Why does this happen?

I am getting a string from another class to compare it to a current string, but the if statement didn’t work because there is something wrong with the string. When I tried to check the length, they differ. How is this possible?

receivedCom = “go”;

  public string checkaction(string receivedCom)
        {

            print ("-------" + receivedCom + "-------" + receivedCom.Length); //Just to show there isnt any white spaces behind or infront --> OUTPUT IS "-------go-------3"
            print (receivedCom + receivedCom.Replace(" ", "").Length); //Tried removing white spaces if there were any --> OUTPUT "go3"
            string x = receivedCom.Remove(receivedCom.Length-1); 
            print (x + " " +x.Length); --> OUTPUT IS "go 2" (Correct lenght, but if still doesnt want to work with it)

            if("go".Equals(x)){
            return "yes";
            }
            else{return "";}
        }

Either something strange is going on, or I’m losing it.

This has been done in a CS script. (Used by Unity.)

UPDATE:

Running the code provided by Jon Skeet, this is my Results

Lenght: 3
receivedCom[0] = 103
receivedCom[1] = 111
receivedCom[2] = 13

UPDATE : How i Came to get a “carriage return”

void Start () {

        player = GameObject.FindWithTag("Player");
        script = (PlayerScript) player.GetComponent(typeof(PlayerScript));

        Process p = new Process();
        p.StartInfo.FileName = @"F:\ReceiveRandomInput.exe"; //This exe generates random strings like "go" "start" etc as a console application


        p.StartInfo.Arguments = "arg0 arg1 arg2 arg3 arg4 arg5";
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        //add event handler when output is received
        p.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {


        data = e.Data;  //THIS DATA is what i sent though to the other class (one with the carriage return in
        received = true;
        };

        p.Start();
        p.BeginOutputReadLine();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:33:19+00:00Added an answer on June 14, 2026 at 12:33 am

    How is this possible?

    You’ve shown there isn’t any whitespace. That doesn’t mean there isn’t a non-printable character.

    The simplest diagnostic is to just print out the “odd” Unicode value:

    print((int) receivedCom[receivedCom.Length - 1]);
    

    I’m guessing it’ll be 0, and it’s just an off-by-one error in how you’re reading the data.

    EDIT: Of course to show exactly what’s in the string, just print everything:

    print ("Length: " + receivedCom.Length);
    for (int i = 0; i < receivedCom.Length; i++)
    {
        print("receivedCom[" + i + "] = " + (int) receivedCom[i];
    }
    

    If you could edit the result of that into the question, we can make progress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does this mean I can't update another table from a trigger if I'm using
Does this look like it should work? I'm wanting to generate directions from one
(int)(33.46639 * 1000000) returns 33466389 Why does this happen?
What happens in the following code? Does the synchronization work? This is an interview
Does this work well as a Singleton in actionscript? i.e. are there any gotchas
In my current project there is a Form class which looks like this: public
UPDATE: This isn't about getting it to compile. The question is, why does the
I'm getting this error: Warning: stristr() expects parameter 1 to be string, array given
Does this code always evaluate to false? Both variables are two's complement signed ints.
Does this function has the same behavior that memset ? inline void SetZeroArray( void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.