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

  • Home
  • SEARCH
  • 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 7662239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:44:59+00:00 2026-05-31T13:44:59+00:00

I am looking to split a string containing several records into individual items in

  • 0

I am looking to split a string containing several records into individual items in a stringlist. (Delphi 7.)

Here is the raw text in a single long string:

+CMGL: 0,”REC UNREAD”,”+27832729407″,,”12/03/17,21:32:05+08″This is the text in message 1+CMGL: 1,”REC UNREAD”,”+27832729407″,,”12/03/17,21:32:30+08″And this is the text in message 2+CMGL: 2,”REC UNREAD”,”+27832729407″,,”12/03/17,21:32:58+08″This is the text in message 3+CMGL: 3,”REC UNREAD”,”+27832729407″,,”12/03/17,21:33:19+08″And finally text in message 4+CMGL: 4,”REC UNREAD”,”+27832729407″,,”12/03/17,21:34:03+08″Ok one more the the text in 5th messageOK

I received it from a GSM device. The final character 2 characters are always OK, being the result from my GSM device.

This is the result I require:

+CMGL: 0,"REC UNREAD","+27832729407",,"12/03/17,21:32:05+08"This is the text in message 1
+CMGL: 1,"REC UNREAD","+27832729407",,"12/03/17,21:32:30+08"And this is the text in message 2
+CMGL: 2,"REC UNREAD","+27832729407",,"12/03/17,21:32:58+08"This is the text in message 3
+CMGL: 3,"REC UNREAD","+27832729407",,"12/03/17,21:33:19+08"And finally text in message 4
+CMGL: 4,"REC UNREAD","+27832729407",,"12/03/17,21:34:03+08"Ok one more the the text in 5th message

(each +CGML is the start of a new line)

I can work with it from here as it is uniform. I would appreciate any help. I hope this makes sense.

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-05-31T13:45:01+00:00Added an answer on May 31, 2026 at 1:45 pm

    You can use the PosEx and Copy functions to build a function to split the string.

    Check this sample

    {$APPTYPE CONSOLE}
    
    uses
      Classes,
      StrUtils,
      SysUtils;
    
    
    const
      GSMMessage=
      '+CMGL: 0,"REC UNREAD","+27832729407",,"12/03/17,21:32:05+08"This is the text in message 1+CMGL: 1,"REC UNREAD","+27832729407",,"12/03/17,21:32:30+08"And this is the text in message 2+CMGL: 2,"REC UNREAD","+27832729407",,"12/03/17,21:32:58+08"'+
      'This is the text in message 3+CMGL: 3,"REC UNREAD","+27832729407",,"12/03/17,21:33:19+08"And finally text in message 4+CMGL: 4,"REC UNREAD","+27832729407",,"12/03/17,21:34:03+08"Ok one more the the text in 5th messageOK';
    
    
    procedure SplitGSMMessage(const Msg : String; List : TStrings);
    const
     StartStr='+CMGL';
    Var
     FoundOffset : Integer;
     StartOffset : Integer;
     s           : String;
    begin
      List.Clear;
    
        StartOffset := 1;
        repeat
          FoundOffset := PosEx(StartStr, Msg, StartOffset);
          if FoundOffset <> 0 then
          begin
           s := Copy(Msg, StartOffset, FoundOffset - StartOffset);
           if s<>'' then List.Add(s);
           StartOffset := FoundOffset + 1;
          end;
        until FoundOffset=0;
    
        // copy the remaining part
        s := Copy(Msg, StartOffset, Length(Msg) - StartOffset + 1);
        if s<>'' then List.Add(s);
    end;
    
    var
      List : TStrings;
    begin
      try
        List:=TStringList.Create;
        try
         SplitGSMMessage(GSMMessage, List);
         Writeln(List.Text);
        finally
         List.Free;
        end;
    
      except
        on E: Exception do Writeln(E.ClassName, ': ', E.Message);
      end;
      Readln;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm looking to do is split data from string into an array. Here's
I'm looking for the fastest solution , to split a string into parts, without
I'm looking for a way to split a string containing HTML in to two
Looking for some help! I need to split a string at the last occurrence
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I am looking for a algorithm that takes a string and splits it into
I'm looking to split space-delimited strings into a series of search terms. However, in
I'm looking for a way, in .NET, to split a string while ignoring split
I need to split the string thisIs12MyString to an array looking like [ this,
I would like to split a string according to the title in a single

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.