1. Khái niệm

– Xâu là một dãy kí tự trong bảng mã ASCII. Mỗi kí tự được gọi là một phần tử của xâu.

– Số lượng kí tự trong xâu được gọi là độ dài của xâu .

– Xâu có độ dài bằng 0 gọi là xâu rỗng.

– Tham chiếu tới phần tử trong xâu được xác định thông qua chỉ số của phần tử trong xâu.

     <Tên biến xâu>[chỉ số]

– Cách khai báo biến xâu:

 var <tên biến xâu> : string [độ dài lớn nhất của xâu] ;

– Ví dụ:

  • Ten : String[10] ;
  • Ho_dem : String[50] ;
  • Que : String ;

* Chú ý:

  • Nếu không khai báo độ dài tối đa cho biến xâu kí tự thì độ dài ngầm định của xâu là 255 .
  • Hằng xâu kí tự được đặt trong cặp nháy đơn ‘ ’.

2. Các thao tác xử lí xâu

– Phép ghép xâu: Kí hiệu là dấu cộng (+)

Ví dụ: ‘Ha’  + ‘ Noi’ + ‘ – ’ + ‘Viet Nam’ => cho kết quả là ‘Ha Noi – Viet Nam’

– Phép so sánh: <, <=, >, >=, = , <>.

  • Xâu A là lớn hơn xâu B nếu như kí tự đầu tiên khác nhau giữa chúng kể từ trái sang trong xâu A có mã ASCII lớn hơn
  • Nếu A và B là các xâu có độ dài khác nhau và A là đoạn đầu của B thì A là nhỏ hơn B.
  • Hai xâu được coi là bằng nhau nếu chúng hoàn toàn giống nhau.
  • Ví dụ:
    • (‘ABC’=’ABC’).
    • (‘ABCDEF’<’ABCFGH’).
    • (‘ABC’<’ABCDEF’).

– Một số thủ tục chuẩn dùng để xử lí xâu:

  • Hàm Delete(St,vt,n) Xoá n kí tự của xâu st bắt đầu từ vị trí vt. Ví dụ:

     Var St: String[20];
Begin
St := ‘CHUOI CHUA BI CAT’;
St := Delete(St,6,5);
Write(St);
End.

  • Hàm Insert(S1,S2,vt): Chèn xâu S1 vào xâu S2 bắt đầu từ vị trí vt của S2. Ví dụ:

     Var St, Obj: String[20];
Begin
St := ‘CHUOI THEM’;
Obj := ‘DA  ’;
Insert(obj,St,7);
Write(St);
End.

  •  Hàm Val(St,x,m): Đổi giá trị xâu St thành số ghi giá trị vào biến X, nến không đổi được thì vị trí gây lỗi ghi trong m, nếu đổi thành công thì m = 0. Ví dụ:

     Var  St: String[20];
X: Real;
Code: Integer;
Begin
St := ‘789.789’;
Val(St, X, Code);
          Writeln(‘X = ’ ,X, ’ ; Code = ‘ , Code);
          St := ‘789A789’;
          Val(St, X, Code);
          Writeln(‘X = ’ ,X, ’ ; Code = ‘ , Code); 
     End.

  • Hàm Str(X, St): Chuyển số X thành xâu kí tự lưu trong St. Ví dụ:

     Var St: String[20]; S: Real;
Begin

          S := 987987987;
          Str(S:9:0,St);
          Write(St);
End.

  • Hàm Length(St): Cho kết quả là một số nguyên chỉ độ dài của chuỗi (số ký tự của chuỗi). Ví dụ: Để viết một dòng ở giữa màn hình ta làm như sau:

     GotoXY((80-Length(st))div 2, 12);
Write(st);

  • Hàm Copy(St, Pos, n): Kết quả trả về của hàm là một chuỗi, trích từ chuỗi St, chéptừ ví trí Pos và chép n ký tự. Ví dụ:

     Var St, Obj: String[20];
Begin
St := ‘TURBO PASCAL 7.0’;
Obj := Copy(st,7,6);
Write(Obj);
End.

  • Hàm Concat(St1, St2, St3,…Stn): Cho kết quả là một chuỗi mới được ghép từ các chuỗi St1, St2, St3,…, Stn theo thứ tự truyền vào hàm. Kết quả này giống như phép cộng chuỗi.
  • Hàm Pos(Obj, St): Cho kết quả là một vị trí đầu tiên của Obj trong chuỗi St. Nếu không tìm thấy thì hàm trả về kết quả là 0. Ví dụ:

     Var St, Obj: String[20];
Begin
St := ‘TURBO PASCAL 7.0’;
Obj := ‘PASCAL’;
Write(Pos(Obj, St));
End.

  • Hàm Pos(S1, S2): Tìm vị trí xuất hiện đầu tiên của S1 trong S2.
  • Hàm Upcase(ch): Cho chữ cái viết hoa tưng ứng với chữ thường trong ch.

116 BÌNH LUẬN

  1. Hi there would you mind letting me know which hosting company
    you’re working with? I’ve loaded your blog in 3 different web
    browsers and I must say this blog loads a lot quicker then most.
    Can you suggest a good hosting provider at a honest price?
    Cheers, I appreciate it!

  2. What’s Taking place i am new to this, I stumbled upon this I’ve discovered It absolutely helpful and it has helped
    me out loads. I hope to contribute & assist other customers like its aided
    me. Good job.

  3. I do trust all of the ideas you’ve presented in your post.
    They’re very convincing and can definitely work.
    Nonetheless, the posts are very brief for beginners.

    May just you please extend them a little from subsequent time?
    Thank you for the post.

  4. It is the best time to make a few plans for the future and it’s time to be happy.
    I’ve learn this publish and if I may I desire to
    recommend you few interesting things or tips.
    Perhaps you can write next articles relating to this article.
    I desire to read even more issues about it!

  5. Thank you a lot for sharing this with all of
    us you actually recognize what you’re speaking about! Bookmarked.

    Please also visit my web site =). We will have a link exchange arrangement among us

  6. Thank you for any other great post. The place else could anyone get that type of info in such an ideal
    means of writing? I have a presentation subsequent week, and I’m
    at the look for such information.

  7. I absolutely love your blog and find the majority of your post’s to be precisely what
    I’m looking for. Would you offer guest writers to write content for you personally?
    I wouldn’t mind composing a post or elaborating
    on most of the subjects you write with regards to
    here. Again, awesome web site!

  8. Pretty component to content. I just stumbled upon your website and in accession capital to assert that I get in fact
    enjoyed account your blog posts. Anyway I will be subscribing on your augment and
    even I fulfillment you get right of entry to persistently fast.

  9. qDz4Ng Usually I don at learn post on blogs, however I wish to say that this write-up very compelled me to check out and do it! Your writing taste has been surprised me. Thanks, quite nice article.

  10. I am extremely impressed with your writing skills as well as
    with the layout on your blog. Is this a paid theme
    or did you customize it yourself? Either way keep up the excellent quality writing, it’s rare to see a great blog like this one nowadays.

  11. Right here is the perfect website for anyone who hopes to find out about this topic.
    You realize so much its almost hard to argue with you (not that I
    really would want to…HaHa). You definitely
    put a brand new spin on a topic that has been discussed for years.
    Great stuff, just excellent!

  12. Having read this I thought it was really enlightening. I appreciate you
    taking the time and effort to put this information together.

    I once again find myself spending a lot of time both
    reading and posting comments. But so what, it was still worthwhile!

  13. An impressive share! I’ve just forwarded this onto a co-worker who had been doing a little research on this.
    And he in fact ordered me dinner due to the fact that I found
    it for him… lol. So let me reword this….
    Thank YOU for the meal!! But yeah, thanks for spending some time to
    discuss this matter here on your web site.

  14. I was suggested this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my problem. You are incredible! Thanks!

  15. This very blog is no doubt educating as well as diverting. I have found a bunch of handy advices out of it. I ad love to visit it again and again. Thanks a bunch!

  16. whoah this blog is fantastic i love reading your articles. Keep up the good work! You know, many people are looking around for this information, you could help them greatly.

  17. Just desire to say your article is as amazing.
    The clarity to your publish is simply excellent
    and i can suppose you’re an expert on this subject.
    Well together with your permission let me to snatch your RSS feed to keep updated with coming near near post.
    Thank you a million and please continue the gratifying
    work.

  18. Wow, amazing blog layout! How lengthy have you ever been running a blog for?
    you made blogging glance easy. The total glance of your website is excellent, let alone the content!

  19. It’s a pity you don’t have a donate button! I’d certainly donate to this superb blog!
    I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will share this website with my Facebook
    group. Talk soon!

  20. Wow that was unusual. I just wrote an extremely long comment but after
    I clicked submit my comment didn’t show up. Grrrr…
    well I’m not writing all that over again. Anyways, just wanted to
    say excellent blog!

  21. Hey, I think your website might be having browser compatibility
    issues. When I look at your blog site in Safari, it looks
    fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that,
    wonderful blog!

  22. Excellent post. Keep writing such kind of info on your page.
    Im really impressed by your site.
    Hi there, You have done an incredible job. I’ll certainly digg it and for my part recommend
    to my friends. I am sure they’ll be benefited from
    this site.

  23. Your article continually comprise much of really in the lead to date information. Everyplace accomplish you come cheery with this? Merely declaring you are vastly innovative. Thanks again

  24. Very nice post. I just stumbled upon your weblog and wished to say that I have really enjoyed browsing your blog posts. In any case I will be subscribing to your feed and I hope you write again soon!

  25. thank you for all your efforts that you have put in this. Very interesting info. No amount of artificial reinforcement can offset the natural inequalities of human individuals. by Henry P. Fairchild.

  26. You can definitely see your skills within the work you write. The arena hopes for even more passionate writers such as you who are not afraid to say how they believe. All the time go after your heart.

THOÁT KHỎI BÌNH LUẬN

Please enter your comment!
Please enter your name here