Is there a SEARCH command??? HELP!

im using turbo pascel...

and im trying to find a word in a long string for ex.

FREDDI'S#TOWN#666 ELM STREET#RUT-IRED#M#MEXI

i need to pull out "TOWN".. how do i do it???

please anyone..






Comments

  • if i can get this done then i can finished my inverted file plz help.


  • : im using turbo pascel...

    : and im trying to find a word in a long string for ex.

    : FREDDI'S#TOWN#666 ELM STREET#RUT-IRED#M#MEXI

    : i need to pull out "TOWN".. how do i do it???

    : please anyone..







    Hmm, well you could have included more info...

    Will you always be searching for town or will

    the string you are searching for vary?



    Heres a piece of code...im sure you'll be able to use it:



    program search;



    var s, s2, s3 : string;

    x : byte;

    begin



    s := 'FREDDI''S#TOWN#666 ELM ST BLAH BLAH';

    s2 := 'TOWN';



    for x := 1 to length(s)-length(s2) do

    begin;

    s3 := copy(s,x,length(s2));

    if s3 = s2 then break;

    end;

    writeln(s3);

    end.





    "s" is the string you are searching

    "s2" is what you are searching for



    "s3" is used with the copy function to get an exerpt from "s" the size of "s2", then compares "s2" and "s3", exiting the search loop if they match. im sure the code could be improved, i just threw it together



    Hope that solves your prob ;)






  • : im using turbo pascel...

    : and im trying to find a word in a long string for ex.

    : FREDDI'S#TOWN#666 ELM STREET#RUT-IRED#M#MEXI

    : i need to pull out "TOWN".. how do i do it???

    : please anyone..

    :



    var

    FinalStr, CutString : string;



    begin

    FinalStr := 'FREDDI'S#TOWN#666 ELM STREET#RUT-IRED#M#MEXI';

    CutString := 'TOWN';



    Delete(FinalStr, pos(CutStr, FinalStr), Length(CutStr));

    end;



    I haven't tried this method in Pascal but it should work.



    Hope this can help you.



    Phase_Zero


  • There is a "STRINGSEARCH-COMMAND" in Turbo Pascal.



    It is the FUNCTION Pos(Substring,String)



    Where:

    Substring is the "word" you are searching.

    String is the "text" where you searching.



    Pos returns an integer value that is the index of the first character of Substring within String. If Substring is not found, Pos returns zero.



    I hope this will help you..






Sign In or Register to comment.

Howdy, Stranger!

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

Categories