Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

모듈12 String문자열들 Exercise 3 이슈 #2

Open
pioneerprizehun opened this issue Jul 20, 2022 · 0 comments
Open

모듈12 String문자열들 Exercise 3 이슈 #2

pioneerprizehun opened this issue Jul 20, 2022 · 0 comments

Comments

@pioneerprizehun
Copy link

pioneerprizehun commented Jul 20, 2022

unit Unit_ch12_3;

interface

uses
  System.Classes, Vcl.Controls, Winapi.Messages, System.SysUtils, System.Variants, Vcl.Graphics,
  Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.StrUtils;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i:integer;
  Cnt:integer;
  s:string;
begin
  Cnt := 0;
  s := Edit1.Text;
  for i := 1 to Length(s) do
    if s[i] =  '.' then
       Cnt := Cnt + 1;
   ShowMessage(InTtoStr(Cnt));
end;
end.

위코드는 Exercise 3 의 코드입니다.

예제프로젝트를 실행시 작동이 잘되지만
직접 작성하여 실행해보면 되지않습니다.

문제는

밑에서부터 위로6번째줄

  for i := 0 to Length(s) do```
 에있습니다.

문자열의 첫번째는 길이가 들어 있고, 이곳은 직접 읽고 쓸수 없습니다.

그래서 첫번째를 건너 띄고, 1 인덱스부터 for 문을 돌려야 합니다. 

아래의 코드로 작성시 작동되오니 혹시 오류가생겨 막히는분들에게 참고가되는 글이였으면좋겠습니다.

for i := 1 to Length(s) do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant