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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:12:48+00:00 2026-06-15T07:12:48+00:00

I’m not sure how to title this, let alone explain it well, but here

  • 0

I’m not sure how to title this, let alone explain it well, but here it goes.

I currently have this method:

- (void) receivedData:(NSString *)data {
}

It triggers when serial data is read. The serial data is coming in as :<DMX>255,23,1,4,6</DMX> problem is, it’s not coming in as one unified string. It comes in pieces. Like, <DM , X>255 , ,23,1,4, , etc. It’s random so I can’t track it. Sometimes it sends the whole thing, others it sends every couple characters at a time. It is what it is.

How, in my code, can I wait for the whole thing to come in (starting at <DMX> and ending at </DMX>) and then create an NSString? Maybe as the data comes in, store the pieces, wait for the end </DMX>, then combine them together?

Thanks!

  • 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-15T07:12:50+00:00Added an answer on June 15, 2026 at 7:12 am
    1. If You are parsing XML, and have an option of using XML parser – use it (there are builtin XML Parsers in iOS/OSX, as well as numerous other options).

    2. If however, you decide to code this instead…

    Create NSMutableString ivar and keep adding (appendString) to it as you receive data…
    Then keep track of whether you met your start/end tags already…

    Something along these lines..

    In MyClass.h:

    @interface Myclass : NSObject
    {
        NSMutableString *buffer, *tmpBuffer;
        int status; // 0=waiting for <DMX>, 1=recording, 2=done
    }
    

    In MyClass.m:

    -(id) init {
      if(self = [super init]) {
        buffer = [[NSMutableString alloc] init];
        tmpBuffer = [[NSMutableString alloc] init];
        status = 0;
      }
      return self;
    }
    
    -(void) receivedData:(NSString *)data {
      if(status == 2) return; // already done
    
      // status=0 means we are still looking for start tag
      if(status == 0) {
        // add new data to last examined chunk (if any)
        [tmpBuffer appendString:data];
    
        // try to locate the open tag inside the tmpBuffer
        NSRange range = [tmpBuffer rangeForString:@"<DMX>" options:NSCaseInsensitiveSearch];
    
        // if found, store the portion after the start tag into buffer
        if(range.location != NSNotFound) {
          range.length = [tmpBuffer length] - range.location + 5; // 5 is length of start tag...
          [buffer setString:[tmpBuffer substringWithRange:range]];
          status = 1; // set status to 1 so we know recording started
        } else {
          // store last examined chunk
          [tmpBuffer setString:data];
        }
      }
      else {
        [buffer appendString:data];
        NSRange range = [buffer rangeForString:@"</DMX>" options:NSCaseInsensitiveSearch];
        if(range.location != NSNotFound) {
          range.length = [buffer length] - range.location;
          [buffer deleteCharactersInRange:range];
          status = 2;
        }
      }
    }
    
    -(void) dealloc {
      [buffer release];
      [tmpBuffer release];
      [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.