Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "מחרוזות של תווים. מבוא לתכנות למנע"ס - שבוע מספר 5 - מאיר קומר - סמסטר ב' - תשס"ו מחרוזות - Strings Dim s As String s = “hello” s = s & “kita” או s ="— Presentation transcript:

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

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

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

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

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

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

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

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


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

Similar presentations


Ads by Google