Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

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

Report
Parse string Posted by BobJames on 18 Jun 2005 at 1:18 PM
Hello,

I have string like this:

...ab...abc.....def


the dots are spaces. How can I count from start of string to the end of first set of chars that are not spaces.

Thanks
Bob
Report
Re: Parse string Posted by zibadian on 18 Jun 2005 at 2:07 PM
: Hello,
:
: I have string like this:
:
:
: ...ab...abc.....def
: 

:
: the dots are spaces. How can I count from start of string to the end of first set of chars that are not spaces.
:
: Thanks
: Bob
:
Here is part of a small code, which should help you on your way:
  for i := 1 to Length(s) do
    if s[i] <> ' ' then // Check if i-th character isn't a space
    begin
      {Do Something}
    end;

Report
Re: Parse string Posted by BobJames on 18 Jun 2005 at 7:41 PM
: : Hello,
: :
: : I have string like this:
: :
: :
: : ...ab...abc.....def
: : 

: :
: : the dots are spaces. How can I count from start of string to the end of first set of chars that are not spaces.
: :
: : Thanks
: : Bob
: :
: Here is part of a small code, which should help you on your way:
:
:   for i := 1 to Length(s) do
:     if s[i] <> ' ' then // Check if i-th character isn't a space
:     begin
:       {Do Something}
:     end;
: 

:

Hello....thanks for reply. I can get index of spaces and even the ab chars. I just can't copy the ' ab' then delete from string and do over to get the rest. Sorry for stupid.

Bob

Report
Re: Parse string Posted by zibadian on 18 Jun 2005 at 9:41 PM
: : : Hello,
: : :
: : : I have string like this:
: : :
: : :
: : : ...ab...abc.....def
: : : 

: : :
: : : the dots are spaces. How can I count from start of string to the end of first set of chars that are not spaces.
: : :
: : : Thanks
: : : Bob
: : :
: : Here is part of a small code, which should help you on your way:
: :
: :   for i := 1 to Length(s) do
: :     if s[i] <> ' ' then // Check if i-th character isn't a space
: :     begin
: :       {Do Something}
: :     end;
: : 

: :
:
: Hello....thanks for reply. I can get index of spaces and even the ab chars. I just can't copy the ' ab' then delete from string and do over to get the rest. Sorry for stupid.
:
: Bob
:
:
Then I suggest a nested while-do loop:
  while s <> '' do
  begin
    Part := '';
    while s[1] = ' ' do // Move all the spaces into part
    begin
      Part := Part + s[1];
      Delete(s, 1, 1);
    end;
    while s[1] <> ' ' do // Move all the letters into part
    begin
      Part := Part + s[1];
      Delete(s, 1, 1);
    end;
    // Now part contains the left-most spaces and letters from s
  end;

This code looks complex, but it is quite easy to follow in the debugger. I would suggest that you look at what happens to s and Part while stepping through the code.
Report
Re: Parse string Posted by BobJames on 19 Jun 2005 at 7:56 AM
: Then I suggest a nested while-do loop:
:
:   while s <> '' do
:   begin
:     Part := '';
:     while s[1] = ' ' do // Move all the spaces into part
:     begin
:       Part := Part + s[1];
:       Delete(s, 1, 1);
:     end;
:     while s[1] <> ' ' do // Move all the letters into part
:     begin
:       Part := Part + s[1];
:       Delete(s, 1, 1);
:     end;
:     // Now part contains the left-most spaces and letters from s
:   end;
: 

: This code looks complex, but it is quite easy to follow in the debugger. I would suggest that you look at what happens to s and Part while stepping through the code.
:

OK....yes I see how it works. Nice. How to stop loop when s=''. Get access violation when string is empty. Seems the inside(?) loop looking for ' ' but finds '' and crash. Maybe boolean?

Bob

Report
Re: Parse string Posted by zibadian on 19 Jun 2005 at 1:29 PM
: : Then I suggest a nested while-do loop:
: :
: :   while s <> '' do
: :   begin
: :     Part := '';
: :     while s[1] = ' ' do // Move all the spaces into part
: :     begin
: :       Part := Part + s[1];
: :       Delete(s, 1, 1);
: :     end;
: :     while s[1] <> ' ' do // Move all the letters into part
: :     begin
: :       Part := Part + s[1];
: :       Delete(s, 1, 1);
: :     end;
: :     // Now part contains the left-most spaces and letters from s
: :   end;
: : 

: : This code looks complex, but it is quite easy to follow in the debugger. I would suggest that you look at what happens to s and Part while stepping through the code.
: :
:
: OK....yes I see how it works. Nice. How to stop loop when s=''. Get access violation when string is empty. Seems the inside(?) loop looking for ' ' but finds '' and crash. Maybe boolean?
:
: Bob
:
:
Yes, after the Delete() check if the string is empty and call Break() to get out of the loop.
Report
Re: Parse string Posted by BobJames on 19 Jun 2005 at 6:12 PM
: : : Then I suggest a nested while-do loop:
: : :
: : :   while s <> '' do
: : :   begin
: : :     Part := '';
: : :     while s[1] = ' ' do // Move all the spaces into part
: : :     begin
: : :       Part := Part + s[1];
: : :       Delete(s, 1, 1);
: : :     end;
: : :     while s[1] <> ' ' do // Move all the letters into part
: : :     begin
: : :       Part := Part + s[1];
: : :       Delete(s, 1, 1);
: : :     end;
: : :     // Now part contains the left-most spaces and letters from s
: : :   end;
: : : 

: : : This code looks complex, but it is quite easy to follow in the debugger. I would suggest that you look at what happens to s and Part while stepping through the code.
: : :
: :
: : OK....yes I see how it works. Nice. How to stop loop when s=''. Get access violation when string is empty. Seems the inside(?) loop looking for ' ' but finds '' and crash. Maybe boolean?
: :
: : Bob
: :
: :
: Yes, after the Delete() check if the string is empty and call Break() to get out of the loop.
:
Yes, Break that is it. Thank you much. You are big help. One more question. Is this consider inner and outer loop? Sorry, just learning.

Bob
Report
Re: Parse string Posted by zibadian on 19 Jun 2005 at 10:07 PM
: : : : Then I suggest a nested while-do loop:
: : : :
: : : :   while s <> '' do
: : : :   begin
: : : :     Part := '';
: : : :     while s[1] = ' ' do // Move all the spaces into part
: : : :     begin
: : : :       Part := Part + s[1];
: : : :       Delete(s, 1, 1);
: : : :     end;
: : : :     while s[1] <> ' ' do // Move all the letters into part
: : : :     begin
: : : :       Part := Part + s[1];
: : : :       Delete(s, 1, 1);
: : : :     end;
: : : :     // Now part contains the left-most spaces and letters from s
: : : :   end;
: : : : 

: : : : This code looks complex, but it is quite easy to follow in the debugger. I would suggest that you look at what happens to s and Part while stepping through the code.
: : : :
: : :
: : : OK....yes I see how it works. Nice. How to stop loop when s=''. Get access violation when string is empty. Seems the inside(?) loop looking for ' ' but finds '' and crash. Maybe boolean?
: : :
: : : Bob
: : :
: : :
: : Yes, after the Delete() check if the string is empty and call Break() to get out of the loop.
: :
: Yes, Break that is it. Thank you much. You are big help. One more question. Is this consider inner and outer loop? Sorry, just learning.
:
: Bob
:
The 2 blue loops are considered to be inner loops, while the black loop is the outer loop. In case of 3+ nested loops, 1 or more loop(s) can be considered to be both.



 

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.