Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help with strings Posted by Glade on 2 Dec 2002 at 8:50 AM
Hi there. I have just studied strings and i have encountered a problem.
I have an htmlfile (.html) with some tags. Now, The specification indicates that a tag should always begin with a < on the first character of a line. It follows that if you find spaces before the '<' you should report an error. Any spaces on the right-hand side should be removed. I know i have to use the pos() function but i couldn't get heads or tails from where to start. Can some1 tell me how to do this?

Thanks
Glade


Report
Re: help with strings Posted by jasonpsage on 2 Dec 2002 at 12:30 PM
: Hi there. I have just studied strings and i have encountered a problem.
: I have an htmlfile (.html) with some tags. Now, The specification indicates that a tag should always begin with a < on the first character of a line. It follows that if you find spaces before the '<' you should report an error. Any spaces on the right-hand side should be removed. I know i have to use the pos() function but i couldn't get heads or tails from where to start. Can some1 tell me how to do this?
:
: Thanks
: Glade
:
:
:
Well, Glade, I'm not exactly Sure Why you can't make heads or tails of the POS function but I'll try to give you some alternative ones that MIGHT help you. I don't claim that these are the most efficient ways to do what they do, but they work for me..so far just fine. You'll see I use ANSISTRINGS (This is tested on 1.0.6 FreePascal from www.freepascal.org which is compatible with most of Borland so I hope this helps)
FIRST ROUTINE TO HELP YOU (is basically my version of POS):
CUT BEGIN ------------------------------------------------------------
//=============================================================================
function i4InStr(p_saSearchMe: AnsiString; p_chSearchFor: char): LongInt;
//=============================================================================
// return index to first position where p_chSearchFor is found 0=no find
//=============================================================================
var i4Pos: LongInt;
begin
  i4InStr:=0;
  if length(p_saSearchMe)>0 then
  begin
    i4Pos:=0;
    repeat
      i4Pos+=1;
      if p_saSearchMe[i4Pos]=p_chSearchFor then 
      begin
        i4InStr:=i4Pos;
        i4Pos:=0;
      end;
    until (i4Pos=0) or (i4Pos=length(p_saSearchMe));
  end;
end;  
//=============================================================================

CUT END ------------------------------------------------------------





-=/Here Is A Routine to help Strip Spaces or whatever/=-
CUT BEGIN ------------------------------------------------------------
// remove a chunk out of a string p_s: start of cut, p_l:length of cut
//*****************************************************************************
function saCut(p_sa: AnsiString; p_s, p_l: LongInt):AnsiString;
//*****************************************************************************
var saTempLeft: AnsiString;
    saTempRight: AnsiString;
    t: LongInt;
begin
  saCut:=p_sa;
  if (length(p_sa)>0) and (p_s<=length(p_sa)) and 
     ((p_s+p_l-1)<=Length(p_sa)) and (p_l<>0) then
  begin
    if p_s>1 then
    begin
      for t:=1 to p_s-1 do saTempLeft:=saTempLeft+p_sa[t];
    end
    else
    begin
      saTempLeft:='';
    end;
    if (p_s+p_l-1)<length(p_sa) then
    begin
      for t:=(p_s+p_l) to length(p_sa) do saTempRight:=saTempRight+p_sa[t];
    end
    else
    begin
      saTempRight:='';
    end;
    saCut:=saTempLeft+saTempRight;
  end;
end;
//*****************************************************************************

CUT END ------------------------------------------------------------









Report
Re:Re: help with strings Posted by Glade on 3 Dec 2002 at 2:18 AM
thanks for the help but I would want to use the pos() function for this so that I'd know how to do it. Thanks
Glade
Report
Re: help with strings Posted by zibadian on 3 Dec 2002 at 2:37 AM
: Hi there. I have just studied strings and i have encountered a problem.
: I have an htmlfile (.html) with some tags. Now, The specification indicates that a tag should always begin with a < on the first character of a line. It follows that if you find spaces before the '<' you should report an error. Any spaces on the right-hand side should be removed. I know i have to use the pos() function but i couldn't get heads or tails from where to start. Can some1 tell me how to do this?
:
: Thanks
: Glade
:
Here is a simple code to report the errors in the HTML and remove the spaces. This code takes just 1 line of HTML. You can easily adapt this code to process multiple lines, by for example creating a procedure from it.
begin
  if Pos('<', Line) > 1 then { If position in line is not 1st character }
    writeln('Error in line');
  while Line[Length(Line)]=' ' do { while any spaces at the end of the string }
    delete(Line, Length(Line), 1); { remove it }
  end;




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.