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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:19:17+00:00 2026-05-28T05:19:17+00:00

I have a NSData of bytes from where I want to subtract a string.

  • 0

I have a NSData of bytes from where I want to subtract a string. The NSData object looks like this

01 00 00 04 40 00 00 00 00 41 41 41 41 48 47 5A 30 65 58 42 4E 4E 45 45 67 41 
41 41 41 41 45 30 30 51 53 42 74 63 44 51 79 61 58 4E 76 62 51 41 41 41 2B 39 
74 62 32 39 32 41 41 41 41 62 47 31 32 61 47 51 41 41 41 41 41 71 67 59 35 79 
36 6F 47 4F 63 73 41 41 4B 78 45 41 41 43 34 41 41 41 42 41 41 41 42 41 41 41 
41 41 41 41 41 41 41 41 41 41 41 41 41 41 51 41 41 41 41 41 41 41 41 41 41 41

I want to extract everything from the first occurrence of “40 00 00 00” to the first occurrence of “34”

How can I do that?

Thanks

marc

  • 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-28T05:19:18+00:00Added an answer on May 28, 2026 at 5:19 am

    Not sure which bytes you want, here is extracted data in the range between “40 00 00 00” to the first occurrence of “34” and the data with that range removed:

    const NSUInteger dataLength = 130;
    unsigned char dataBytes[dataLength] = {
    0x01,0x00,0x00,0x04,0x40,0x00,0x00,0x00,0x00,0x41,0x41,0x41,0x41,0x48,0x47,0x5A,
    0x30,0x65,0x58,0x42,0x4E,0x4E,0x45,0x45,0x67,0x41,0x41,0x41,0x41,0x41,0x45,0x30,
    0x30,0x51,0x53,0x42,0x74,0x63,0x44,0x51,0x79,0x61,0x58,0x4E,0x76,0x62,0x51,0x41,
    0x41,0x41,0x2B,0x39,0x74,0x62,0x32,0x39,0x32,0x41,0x41,0x41,0x41,0x62,0x47,0x31,
    0x32,0x61,0x47,0x51,0x41,0x41,0x41,0x41,0x41,0x71,0x67,0x59,0x35,0x79,0x36,0x6F,
    0x47,0x4F,0x63,0x73,0x41,0x41,0x4B,0x78,0x45,0x41,0x41,0x43,0x34,0x41,0x41,0x41,
    0x42,0x41,0x41,0x41,0x42,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
    0x41,0x41,0x41,0x41,0x41,0x41,0x51,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
    0x41,0x41};
    NSData *data = [NSData dataWithBytes:dataBytes length:130];
    
    const NSUInteger startBytesLength = 4;
    unsigned char startBytes[startBytesLength] = {0x40, 0x00, 0x00, 0x00};
    const NSUInteger stopBytesLength = 1;
    unsigned char stopBytes[stopBytesLength] = {0x34};
    
    
    NSData *startData = [NSData dataWithBytes:startBytes length:startBytesLength];
    NSData *stopData  = [NSData dataWithBytes:stopBytes  length:stopBytesLength];
    NSRange startRange = [data rangeOfData:startData options:0 range:NSMakeRange(0, dataLength)];
    NSUInteger start = startRange.location;
    
    NSRange stopRange  = [data rangeOfData:stopData  options:0 range:NSMakeRange(start+startBytesLength, dataLength-(start+startBytesLength))];
    NSUInteger length = stopRange.location - start;
    NSUInteger stopLocation = stopRange.location+stopBytesLength;
    
    NSData *extractData = [data subdataWithRange:NSMakeRange(start, length)];
    NSLog(@"extractData: %@", extractData);
    
    NSMutableData *newData = [NSMutableData data];
    [newData appendData:[data subdataWithRange:NSMakeRange(0, start)]];
    [newData appendData:[data subdataWithRange:NSMakeRange(stopLocation, dataLength-stopLocation)]];
    NSLog(@"newData: %@", newData);
    

    NSLog output:

    extractData: <00414141 4148475a 30655842 4e4e4545 67414141 41414530
    30515342 74634451 7961584e 76625141 41412b39 74623239 32414141
    41624731 32614751 41414141 41716759 3579366f 474f6373 41414b78
    45414143>

    newData: <01000004 41414142 41414142 41414141 41414141 41414141
    41414141 41514141 41414141 41414141 41>

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

Sidebar

Related Questions

i have a NSData object. I want to convert it to a string, pass
I have UTF-8 encoded NSData from windows server and I want to convert it
I have an original NSData type which contains let's say 100 bytes. I want
I have a NSData object coming back from my server, it varies in its
I have an NSData that I would like to read as an NSInputStream. This
I have code like this: NSData *data = [NSData dataWithContentsOfURL:objURL]; const void *buffer =
I have a NSData object, i need to convert it a NSDictionary object. NSData
I have a problem with this code right here: - (void)fetchedData:(NSData *)responseData { //parse
I have a string that I want as a byte array. So far I
I have a binary file I've loaded using an NSData object. Is there a

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.