Skip to content

Commit a087bd6

Browse files
committed
26-2-21 Updated
1 parent 97367cd commit a087bd6

11 files changed

+899
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//STRING MANIPULATION
2+
//Practice 1
3+
//Finding First word of one string and second word of another string.
4+
//.Visualisation
5+
Str1 ← "Atif Aslam"
6+
Str2 ← "Ricky Martin"
7+
8+
//DECLARATION
9+
DECLARE Str1, Str2, FN, LN : STRING
10+
DECLARE Space, Length : INTEGER
11+
12+
//INITIALISATION
13+
Str1 ← ""
14+
Str2 ← ""
15+
FN ← ""
16+
LN ← ""
17+
Space ← 0
18+
LENGTH ← 0
19+
20+
//INPUT
21+
OUTPUT "Enter Name 1: "
22+
INPUT Str1
23+
24+
OUTPUT "Enter Name 2: "
25+
INPUT Str2
26+
27+
//PROCESS
28+
Space ← LOCATE(Str1, ' ')
29+
FN ← LEFT(Str1, Space-1)
30+
31+
Space ← LOCATE(Str2, ' ')
32+
LENGTH ← LEN(Str2)
33+
LN ← RIGHT(Str2, LENGTH - Space)
34+
35+
//OUTPUT
36+
OUTPUT "Full new name: " + FN + ' ' + LN
37+
---------------------------------------------------------------
38+
39+
Module Module1
40+
41+
Sub Main()
42+
'DECLRATION
43+
Dim Str1, Str2, FN, LN As String
44+
Dim Space, Length As Integer
45+
46+
'INITIALISATION
47+
Str1 = ""
48+
Str2 = ""
49+
FN = ""
50+
LN = ""
51+
Space = 0
52+
Length = 0
53+
54+
'INPUT
55+
Console.Write("Enter Name 1: ")
56+
Str1 = Console.ReadLine()
57+
58+
Console.Write("Enter Name 2: ")
59+
Str2 = Console.ReadLine()
60+
61+
'PROCESS
62+
Space = InStr(Str1, " ")
63+
FN = Left(Str1, Space - 1)
64+
65+
Space = InStr(Str2, " ")
66+
Length = Len(Str2)
67+
LN = Right(Str2, Length - Space)
68+
69+
'OUTPUT
70+
Console.WriteLine("Full new name: " & FN & " " & LN)
71+
72+
Console.ReadKey()
73+
End Sub
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//10) String Validation (Format check.)
2+
3+
//Visualisation
4+
9 → Any digit from 0 TO 9
5+
a → Any small alphabet from a TO z
6+
A → Any capital alphabet from A to Z
7+
8+
PROMPT : Enter the code as "99-aaa-999"
9+
INPUT 1: 12-xyz-789
10+
OUTPUT : Valid input
11+
12+
INPUT 2: 123-jkl
13+
OUTPUT : Invalid input
14+
//----------------------------
15+
//WORKING
16+
//Breakup of "999-aaa-AAA" working
17+
//No.1 --LENGTH--
18+
//No.2 --Fixed characters--
19+
//No.3 --GROUPS-- E.g: 999, aaa, AAA
20+
21+
//----------------------------
22+
//DECLARATIONS
23+
DECLARE Str1: STRING
24+
DECLARE i : INTEGER
25+
DECLARE Char1 : CHARACTER
26+
DECLARE isValid : BOOLEAN //FLAG
27+
28+
//INITIALISATION
29+
Str1 ← ""
30+
i ← 0
31+
Char1 ← ''
32+
isValid ← TRUE
33+
34+
//INPUT
35+
INPUT "Enter the code as ""999-aaa-AAA"": ", Str1
36+
37+
//PROCESS
38+
//Check No. 1 --LENGTH--
39+
IF LEN(Str1) <> 11 THEN isValid = FALSE
40+
41+
//Check No.2 --Fixed characters--
42+
IF MID(Str1, 4, 1) <> '-' AND MID(Str1, 8, 1) <> '-' THEN isValid = FALSE
43+
44+
//Check No.3 --GROUPS-- E.g: 999, aaa, AAA
45+
//Group 1 123 567 91011
46+
FOR i ← 1 TO 3
47+
Char1 ← MID(Str1, i, 1)
48+
IF Char1 < '0' OR Char1 > '9' THEN isValid = FALSE
49+
NEXT i
50+
51+
//Group 2
52+
FOR i ← 5 TO 7
53+
Char1 ← MID(Str1, i, 1)
54+
IF Char1 < 'a' OR Char1 > 'z' THEN isValid = FALSE
55+
NEXT i
56+
57+
//Group 3
58+
FOR i ← 9 TO 11
59+
Char1 ← MID(Str1, i, 1)
60+
IF Char1 < 'A' OR Char1 > 'Z' THEN isValid = FALSE
61+
NEXT i
62+
63+
//OUTPUT
64+
IF isValid THEN
65+
OUTPUT "Valid Code."
66+
ELSE
67+
OUTPUT "Invalid Code."
68+
END IF
69+
70+
------------------------------------
71+
72+
Module Module1
73+
'10) String Validation (Format check.)
74+
Sub Main()
75+
'DECLARATIONS
76+
Dim Str1 As String
77+
Dim i As Integer
78+
Dim Char1 As Char
79+
Dim isValid As Boolean
80+
81+
'INITIALISATION
82+
Str1 = ""
83+
i = 0
84+
Char1 = ""
85+
isValid = True
86+
87+
'INPUT
88+
Console.Write("Enter code to validate as ""999-aaa-AAA"": ")
89+
Str1 = Console.ReadLine
90+
91+
'PROCESS
92+
'Check No. 1 --LENGTH--
93+
If Len(Str1) <> 11 Then isValid = False
94+
95+
'Check No.2 --Fixed characters--
96+
If Mid(Str1, 4, 1) <> "-" And Mid(Str1, 8, 1) <> "-" Then isValid = False
97+
98+
'Check No.3 --GROUPS-- E.g: 999, aaa, AAA
99+
'Group 1 123 567 91011
100+
For i = 1 To 3
101+
Char1 = Mid(Str1, i, 1)
102+
If Char1 < "0" Or Char1 > "9" Then isValid = False
103+
Next i
104+
105+
'Group 2
106+
For i = 5 To 7
107+
Char1 = Mid(Str1, i, 1)
108+
If Char1 < "a" Or Char1 > "z" Then isValid = False
109+
Next i
110+
111+
'Group 3
112+
For i = 9 To 11
113+
Char1 = Mid(Str1, i, 1)
114+
If Char1 < "A" Or Char1 > "Z" Then isValid = False
115+
Next i
116+
117+
'OUTPUT
118+
If isValid Then
119+
Console.WriteLine("Valid Code.")
120+
Else
121+
Console.WriteLine("Invalid Code")
122+
End If
123+
Console.ReadKey()
124+
End Sub
125+
End Module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2) Finding and truncating a character from a string
2+
3+
INPUT Str1
4+
Str1 = "Zafar Ali Khan"
5+
6+
INPUT Char1
7+
Char1 = 'a'
8+
9+
OUTPUT Str2
10+
Str2 = "Zfr Ali Khn"
11+
12+
//Pseudocode
13+
//DECLARATIONS
14+
DECLARE Str1, Str2 : STRING
15+
DECLARE Char1, Char2 : CHARACTER
16+
DECLARE i : INTEGER
17+
18+
//INITIALISE
19+
Str1 ← ""
20+
Str2 ← ""
21+
Char1 ← ''
22+
Char2 ← ''
23+
i ← 0
24+
25+
//INPUT
26+
OUTPUT "Enter string to process: "
27+
INPUT Str1
28+
INPUT "Enter character to truncate from the string: ", Char1
29+
30+
//PROCESS
31+
For i ← 1 TO LEN(Str1)
32+
Char2 ← MID(Str1, i, 1)
33+
IF Char1 <> Char2
34+
THEN
35+
Str2 ← Str2 + Char2
36+
END IF
37+
Next i
38+
39+
//OUTPUT
40+
OUTPUT "Processed string after truncation is: ", Str2
41+
42+
--------------------------------------------------------
43+
Module Module1
44+
'2) Finding and truncating a character from a string
45+
Sub Main()
46+
'Declarations
47+
Dim Str1, Str2 As String
48+
Dim Char1, Char2 As Char
49+
Dim i As Integer
50+
51+
'Initialise
52+
Str1 = ""
53+
Str2 = ""
54+
Char1 = ""
55+
Char2 = ""
56+
i = 0
57+
58+
'Input data
59+
Console.Write("Enter string to process: ")
60+
Str1 = Console.ReadLine
61+
62+
Console.Write("Enter character to truncate from the string: ")
63+
Char1 = Console.ReadLine
64+
65+
'Process
66+
For i = 1 To Len(Str1)
67+
Char2 = Mid(Str1, i, 1)
68+
If Char1 <> Char2 Then
69+
Str2 = Str2 & Char2
70+
End If
71+
Next
72+
73+
'OUTPUT Result
74+
Console.WriteLine("Processed string after truncation is: " & Str2)
75+
76+
Console.ReadKey()
77+
End Sub
78+
79+
End Module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//3) Finding and replacing a character from a string
2+
3+
INPUT Str1
4+
Str1 = "Zafar Ali Khan"
5+
6+
INPUT Char1
7+
Char1 = 'a'
8+
9+
INPUT Char3
10+
Char3 = 'x'
11+
12+
OUTPUT Str2
13+
Str2 = "Zxfxr Ali Khxn"
14+
15+
//Pseudocode
16+
//DECLARATIONS
17+
DECLARE Str1, Str2 : STRING
18+
DECLARE Char1, Char2, Char3 : CHARACTER
19+
DECLARE i : INTEGER
20+
21+
//INITIALISE
22+
Str1 ← ""
23+
Str2 ← ""
24+
Char1 ← ''
25+
Char2 ← ''
26+
Char3 ← ''
27+
i ← 0
28+
29+
//INPUT
30+
INPUT "Enter string to process: ", Str1
31+
INPUT "Enter character to find from the string: ", Char1
32+
INPUT "Enter character to replace with in string: ", Char3
33+
34+
//PROCESS
35+
For i ← 1 TO LEN(Str1)
36+
Char2 ← MID(Str1, i, 1)
37+
IF Char1 <> Char2
38+
THEN
39+
Str2 ← Str2 + Char2
40+
ELSE
41+
Str2 ← Str2 + Char3
42+
END IF
43+
Next i
44+
45+
//OUTPUT
46+
OUTPUT "Processed string after replacementis: ", Str2
47+
---------------------
48+
49+
Module Module1
50+
'3) Finding and replacing of a character from a string
51+
Sub Main()
52+
'Declarations
53+
Dim Str1, Str2 As String
54+
Dim Char1, Char2, Char3 As Char
55+
Dim i As Integer
56+
57+
'Initialise
58+
Str1 = ""
59+
Str2 = ""
60+
Char1 = ""
61+
Char2 = ""
62+
Char3 = ""
63+
i = 0
64+
65+
'Input data
66+
Console.Write("Enter string to process: ")
67+
Str1 = Console.ReadLine
68+
69+
Console.Write("Enter character to find from the string: ")
70+
Char1 = Console.ReadLine
71+
72+
Console.Write("Enter character to replace in the string: ")
73+
Char3 = Console.ReadLine
74+
75+
'Process
76+
For i = 1 To Len(Str1)
77+
Char2 = Mid(Str1, i, 1)
78+
If Char1 <> Char2 Then
79+
Str2 = Str2 & Char2
80+
Else
81+
Str2 = Str2 & Char3
82+
End If
83+
Next
84+
85+
'OUTPUT Result
86+
Console.WriteLine("Processed string after replacement is: " & Str2)
87+
88+
Console.ReadKey()
89+
End Sub
90+
91+
End Module

0 commit comments

Comments
 (0)