Howdy, Stranger!

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

Categories

Geting Info from a String

arash82arash82 Member Posts: 106
Hi there,

I wondered if anyone know a good method to extract serteain information from a string.

Take the following two strings for example:
[italic]
1) Unit1.pas(57) Warning: Variable 'k' might not have been initialized

2) Unit1.pas(31) Hint: Variable 'CharID' is declared but never used in 'TForm1.Button1Click'
[/italic]

As you can see its a compiler info from DCC32.EXE. I want to first know if the string is an "Warning" or a "Hint" (or Error etc). Then I want to extract the Messega ("Variable 'k' might not have been initialized" in string 1). Finally I want to know witch file ("Unit1.pas) and where in the file (line "57") the error warning from.

I would like to put the information in an array of records.


Regards,
Arash

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi there,
    :
    : I wondered if anyone know a good method to extract serteain information from a string.
    :
    : Take the following two strings for example:
    : [italic]
    : 1) Unit1.pas(57) Warning: Variable 'k' might not have been initialized
    :
    : 2) Unit1.pas(31) Hint: Variable 'CharID' is declared but never used in 'TForm1.Button1Click'
    : [/italic]
    :
    : As you can see its a compiler info from DCC32.EXE. I want to first know if the string is an "Warning" or a "Hint" (or Error etc). Then I want to extract the Messega ("Variable 'k' might not have been initialized" in string 1). Finally I want to know witch file ("Unit1.pas) and where in the file (line "57") the error warning from.
    :
    : I would like to put the information in an array of records.
    :
    :
    : Regards,
    : Arash
    :
    This call for a smart use of the Copy(), Delete() and Pos() routines.
    Here is a small code, which splits 1 line into several strings, one for each of your info.
    [code]
    UnitName := Copy(ErrorLine, 1, Pos('(', ErrorLine)-1); // Get the first part
    Delete(ErrorLine, 1, Pos('(', ErrorLine)); // Remove the part taken
    LineNumber := Copy(ErrorLine, 1, Pos(')', ErrorLine)-1);
    Delete(ErrorLine, 1, Pos(')', ErrorLine));
    ErrorType := Copy(ErrorLine, 1, Pos(':', ErrorLine)-1);
    Delete(ErrorLine, 1, Pos(':', ErrorLine));
    Message := ErrorLine;
    [/code]
    You can remove leading and trailing blanks using the Trim() routines. All the variable are strings, which means you need to see to the conversion to the types you need.
  • Shawn CarterShawn Carter Member Posts: 0

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

Sign In or Register to comment.