1 / 18

מחרוזות של תווים

מחרוזות של תווים. hellokita. hello. מחרוזות - Strings. Dim s As String. s = “hello”. s = s & “kita” או s = s + “kita”. פעולות על מחרוזות. 10. מחזירה אורך המחרוזת. Len. Module Module1 Sub Main() Dim word As String word = Console.ReadLine

dysis
Download Presentation

מחרוזות של תווים

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. מחרוזות של תווים

  2. hellokita hello מחרוזות - Strings Dim s As String s = “hello” s = s & “kita” או s = s + “kita” מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  3. פעולות על מחרוזות 10 מחזירה אורך המחרוזת Len Module Module1 Sub Main() Dim word As String word = Console.ReadLine Console.WriteLine(Len(word)) Console.WriteLine(word.Length()) End Sub End Module מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  4. פעולות על מחרוזות he מחזירה תת-מחרוזת משמאל Left a = “hello kita” x = Left (a,2) איזה מחרוזת כמה תוים מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  5. פעולות על מחרוזות o kita מחזירה תת-מחרוזת מימין Right a = “hello kita” x = Right (a,6) איזה מחרוזת כמה תוים מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  6. פעולות על מחרוזות ell מחזירה תת-מחרוזת Mid a = “hello kita” x = Mid (a,2,3) החל מתו- כמה תוים מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  7. תרגול קטן s = “arur haman baruch mordechai” Left (s,10) = Mid (s,1,11)? לא 27 Len (s) arur h Left (s,6) rdechai Right (s,7) haman ba Mid (s,6,8) ord Mid (Right(s,9),2,3) mordechaibaruch Right (s,9) & Mid (s,11,7) מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  8. זה חוקי! "דוד" < "שלמה"? מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו

  9. דוגמא Module Module1 Sub Main() Dim word As String word = Console.ReadLine If (word > "avi") Then Console.WriteLine("Bigger") Else Console.WriteLine("Smaller") End If word = word + "A" Console.WriteLine(word) word = "B" & word Console.WriteLine(word) End Sub End Module

  10. שימוש בסיסי במחרוזת Module Module1 Sub Main() Dim x As String x = Console.ReadLine Console.WriteLine("The Length is " & x.Length()) Console.WriteLine("The first letter is " & x(0)) Console.WriteLine("The second letter is " & x(1)) Console.WriteLine("The third letter is " & x(2)) Console.WriteLine("What will this do??? " & x(2000)) End Sub End Module

  11. שימוש בסיסי במחרוזת Module Module1 Sub Main() Dim x As String x = Console.ReadLine Console.WriteLine("The first letter is " & x(0)) If (x(0) = "A") Then Console.WriteLine("Yeah!") End If If (x(1) = " ") Then Console.WriteLine("Space in second position") End If End Sub End Module

  12. פעולות בסיסיות במחזרות Module Module1 Sub Main() Dim word As String word = Console.ReadLine 'word(0) = "B" ' Won't work! word = word.Replace("a", "b") 'word.Replace("a", "b") also won't work Console.WriteLine("The word now is " & word) word = word.Remove(0, 2) 'takes out first 2 letters Console.WriteLine("The word now is " & word) word = word.Insert(0, "B2") 'add string at position Console.WriteLine("The word now is " & word) End Sub End Module

  13. דוגמא של לולאה במחרוזת Module Module1 Sub Main() Dim x As String Dim i, j As Integer x = Console.ReadLine Console.WriteLine("The Length is " & x.Length()) For i = 0 To x.Length() - 1 For j = 0 To i Console.Write(x(j)) Next Console.WriteLine() Next End Sub End Module

  14. פונקציות עם מחרוזות Module Module1 Function Length(ByVal x As String) As Integer Return x.Length() End Function Sub Main() Dim x As String x = Console.ReadLine Dim y As Integer = Length(x) Console.WriteLine("The length was " & y) End Sub End ModuleA

  15. פונקציה יותר מסובכת Module Module1 Function Change(ByVal x As String) As String Dim i As Integer For i = 0 To x.Length() - 1 If x(i) = "a" Or x(i) = "e" Or x(i) = "i" Then x = x.Remove(i, 1) 'Takes out that letter Console.WriteLine("The word is now " & x) x = x.Insert(i, "Z") 'Puts something else there End If Next Return x End Function Sub Main() Dim word As String word = Console.ReadLine Console.WriteLine("The Word is " & Change(word)) End Sub End Module

  16. פונקציה יותר מסובכת עם REF Module Module1 Sub Change(ByRef x As String) Dim i As Integer For i = 0 To x.Length() - 1 If x(i) = "a" Or x(i) = "e" Or x(i) = "i" Then x = x.Remove(i, 1) 'Takes out that letter Console.WriteLine("The word is now " & x) x = x.Insert(i, "Z") 'Puts something else there End If Next End Sub Sub Main() Dim word As String word = Console.ReadLine Change(word) Console.WriteLine("The Word is " & word) End Sub End Module

  17. פונקציות בוליאנית Module Module1 Function Compare(ByVal word1 As String, ByVal word2 As String) As Boolean Dim i As Integer If (word1.Length <> word2.Length) Then Return False Else For i = 0 To word1.Length() - 1 If word1(i) <> word2(i) Then Return False End If Next End If Return True End Function Sub Main() Dim a, b As String a = Console.ReadLine b = Console.ReadLine If (a = b) Then Console.WriteLine("They are the same") End If If (Compare(a, b)) Then Console.WriteLine("They are still the same") End If End Sub End Module

  18. פונקציות בוליאנית Module Module1 Function Flip(ByVal word1 As String) As Boolean Dim i As Integer For i = 0 To word1.Length() - 1 If word1(i) <> word1(word1.Length() - 1 - i) Then Return False End If Next Return True End Function Sub Main() Dim a, b As String a = Console.ReadLine If (Flip(a)) Then Console.WriteLine("It is a palindrome") Else Console.WriteLine("It isn't") End If End Sub End Module

More Related