Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

String match ( parsing ), masking problems

AjinsaAjinsa Member Posts: 28
Help me. I'm confuse with this problem.
Does anyone could & would help me ?

Problem :
=========
I have string like this,
String1 = It's simple, I can't take it anymore [ Angry ]
String2 = It's simple, I can't take it anymore [Angry]
String3 = Yes it is
String4 = One, two

Available mask,
1. %1, %2
2. %A, %B [ %C ]
3. %A

What I need is a function that can divide that string into parts, based on mask that match
the pattern.

So, the result should be in TStrings format, like this one,

For String1,
%A=It's simple
%B=I can't take it anymore
%C=Angry

For String2,
Error. Can't find mask matched with supplied string.

For String3,
%A=Yes it is

For String4,
%1=One
%2=two

That's the problem. I know that it can be solved with string parsing or tokenizing.
But how ? Or, can I find a component / classes for it ?
Thank's a lot for your help.
I need it for my college work.

Comments

  • DhruvDhruv Member Posts: 59
    var
    coma_pos, bracket_pos: Integer;

    begin
    coma_pos := Pos (',' , string1);
    if (coma_pos <> 0) sub_str1 := Copy (string, 1, coma_pos)
    else sub_str1 := 'Error. String not present.';


    similarly, check for other strings like '[', and set the first parameter of Pos to coma_pos, and for Copy, and parameter would be coma_pos, and 3rd would be (bracket_pos - coma_pos).







    : Help me. I'm confuse with this problem.
    : Does anyone could & would help me ?
    :
    : Problem :
    : =========
    : I have string like this,
    : String1 = It's simple, I can't take it anymore [ Angry ]
    : String2 = It's simple, I can't take it anymore [Angry]
    : String3 = Yes it is
    : String4 = One, two
    :
    : Available mask,
    : 1. %1, %2
    : 2. %A, %B [ %C ]
    : 3. %A
    :
    : What I need is a function that can divide that string into parts, based on mask that match
    : the pattern.
    :
    : So, the result should be in TStrings format, like this one,
    :
    : For String1,
    : %A=It's simple
    : %B=I can't take it anymore
    : %C=Angry
    :
    : For String2,
    : Error. Can't find mask matched with supplied string.
    :
    : For String3,
    : %A=Yes it is
    :
    : For String4,
    : %1=One
    : %2=two
    :
    : That's the problem. I know that it can be solved with string parsing or tokenizing.
    : But how ? Or, can I find a component / classes for it ?
    : Thank's a lot for your help.
    : I need it for my college work.
    :
    :
  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ________ < http://forcoder.org /> free video tutorials and ebooks about | C, Go, C++, Delphi, Assembly, JavaScript, MATLAB, Swift, Java, Python, R, PL/SQL, Objective-C, Scratch, Visual Basic, Perl, PHP, Ruby, Visual Basic .NET, C# Kotlin, Bash, Hack, Crystal, F#, Lisp, FoxPro, Fortran, Alice, Scheme, Rust, Transact-SQL, COBOL, Erlang, ABAP, VBScript, Clojure, Scala, D, Julia, Apex, SAS, Dart, Prolog, Lua, Ada, ML, LabVIEW, Awk, Logo | ____________

Sign In or Register to comment.