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 6231675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:58:37+00:00 2026-05-24T09:58:37+00:00

I am trying to do a string comparison in iOS with a string obtained

  • 0

I am trying to do a string comparison in iOS with a string obtained from a network stream.

The code that reads the stream is:

uint8_t buffer[1024];
int len;
    while ([inputStream hasBytesAvailable]) 
    {
        len = [inputStream read:buffer maxLength:sizeof(buffer)];
        if (len > 0) 
        {
            NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
            [self handleServerResponse: intCommand Response:output];
         }else{
            [self endComms];
         }
     }

The server at the other end always produces responses of 1024 bytes, with chr(0) being placed at the end of the data to fill the buffer.

When I do a string comparison:

if (strCut==@"B") {
   //do something...
}

I always get a negative result, presumably because the string contaings the response and lots of null characters.

I would like to be able to strip empty characters from the buffer when reading the response into the string, but I not having any luck in doing this in iOS.

Help appreciated!

Thanks.

Dave

  • 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-05-24T09:58:38+00:00Added an answer on May 24, 2026 at 9:58 am

    You’re making a bad assumption about why your code is not working.

    Change:

    if (strCut == @"B")
    

    to:

    if ([strCut isEqualToString:@"B"])
    

    For future reference never make assumptions – use a debugger or other tools to verify what the problem is. You might also want to consider reading an introductory book on Objective-C.

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

Sidebar

Related Questions

im trying to return a string value from a method inside my script tag
I am trying to implement postfix-expression evaluation, here is my code: #include<iostream> #include<string.h> using
I am trying string comparison with <c:if test=${dept eq 'account'}></c:if> But this always returns
I'm having a problem with a string creation and comparison that seems to lose
I am trying to setup a comparison based on input from a file (ie
Possible Duplicate: Java string comparison? I was trying to do this: boolean exit =
I am trying to implement string unescaping with Python regex and backreferences, and it
I'm trying to initialize string with iterators and something like this works: ifstream fin(tmp.txt);
I am trying to understand string interning and why is doesn't seem to work
Trying to parse an SQL string and pull out the parameters. Ex: select *

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.