How to resolve the algorithm String case step by step in the BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm String case step by step in the BASIC programming language
Table of Contents
Problem Statement
Take the string alphaBETA and demonstrate how to convert it to:
Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional case conversion functions (e.g. swapping case, capitalizing the first letter, etc.) that may be included in the library of your language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm String case step by step in the BASIC programming language
Source code in the basic programming language
s$ = "alphaBETA"
PRINT UCASE$(s$)
PRINT LCASE$(s$)
S$ = "alphaBETA"
UP$ = "" : FOR I = 1 TO LEN(S$) : C = ASC(MID$(S$, I, 1)) : UP$ = UP$ + CHR$(C - (C > 96 AND C < 123) * 32) : NEXT I : ? UP$
LO$ = "" : FOR I = 1 TO LEN(S$) : C = ASC(MID$(S$, I, 1)) : LO$ = LO$ + CHR$(C + (C > 64 AND C < 91) * 32) : NEXT I : ? LO$
s$ = "alphaBETA"
print "Original string: "; s$
print "To Lower case: "; lower(s$)
print "To Upper case: "; upper(s$)
INSTALL @lib$+"STRINGLIB"
original$ = "alphaBETA"
PRINT "Original: " original$
PRINT "Lower case: " FN_lower(original$)
PRINT "Upper case: " FN_upper(original$)
PRINT "Title case: " FN_title(original$)
10 s$ = "alphaBETA"
20 print "Original string: ";s$
30 print "To Lower case: ";lcase$(s$)
40 print "To Upper case: ";ucase$(s$)
10 rem string case
15 rem rosetta code
20 s$="alphaBETA"
30 print chr$(147);chr$(14)
40 print "The original string is:"
41 print:print tab(11);s$
50 up$="":lo$=""
55 for i=1 to len(s$)
60 c=asc(mid$(s$,i,1))
65 up$=up$+chr$(c or 128)
70 lo$=lo$+chr$(c and 127)
75 next i
80 print:print "Uppercase: ";up$
90 print "Lowercase: ";lo$
' FB 1.05.0 Win64
Dim s As String = "alphaBETA"
Print UCase(s)
Print LCase(s)
Sleep
window 1
CFStringRef s = @"alphaBETA"
print s
print ucase(s)
print lcase(s)
HandleEvents
Public Sub Main()
Dim sString As String = "alphaBETA "
Print UCase(sString)
Print LCase(sString)
End
100 INPUT PROMPT "String: ":TX$
110 PRINT "Lower case: ";LCASE$(TX$)
120 PRINT "Upper case: ";UCASE$(TX$)
input$ ="alphaBETA"
print input$
print upper$( input$)
print lower$( input$)
end
s$ = "alphaBETA"
upper$ = UCase(s$) ;uppercase
lower$ = LCase(s$) ;lowercase
s$ = "alphaBETA"
PRINT "Original string: "; s$
PRINT "To Lower case: "; LCASE$(s$)
PRINT "To Upper case: "; UCASE$(s$)
a$ ="alphaBETA"
print a$ '=> alphaBETA
print upper$(a$) '=> ALPHABETA
print lower$(a$) '=> alphabeta
LET s$ = "alphaBETA"
PRINT "Original string: "; s$
PRINT "To Lower case: "; LCASE$(s$)
PRINT "To Upper case: "; UCASE$(s$)
END
Sub Main()
Const TESTSTRING As String = "alphaBETA"
Debug.Print "initial = " _
& TESTSTRING
Debug.Print "uppercase = " _
& UCase(TESTSTRING)
Debug.Print "lowercase = " _
& LCase(TESTSTRING)
Debug.Print "first letter capitalized = " _
& StrConv(TESTSTRING, vbProperCase)
Debug.Print "length (in characters) = " _
& CStr(Len(TESTSTRING))
Debug.Print "length (in bytes) = " _
& CStr(LenB(TESTSTRING))
Debug.Print "reversed = " _
& StrReverse(TESTSTRING)
Debug.Print "first position of letter A (case-sensitive) = " _
& InStr(1, TESTSTRING, "A", vbBinaryCompare)
Debug.Print "first position of letter A (case-insensitive) = " _
& InStr(1, TESTSTRING, "A", vbTextCompare)
Debug.Print "concatenated with '123' = " _
& TESTSTRING & "123"
End Sub
' Define 's'
Dim s AS String = "alphaBETA"
' Change 's' to Upper Case.
s = s.ToUpper()
' Change 's' to Lower Case.
s = s.ToLower()
:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"→Str9
:"abcdefghijklmnopqrstuvwxyz"→Str0
:Input ">",Str1
:":"+Str1+":"→Str1
:Prompt U
:If U:Then
:For(I,2,length(Str1))
:If inString(Str0,sub(Str1,I,1)) and sub(Str1,I,1)≠":"
:sub(Str1,1,I-1)+sub(Str9,inString(Str0,sub(Str1,I,1)),1)+sub(Str1,I+1,length(Str1)-I)→Str1
:End
:Else
:For(I,2,length(Str1))
:If inString(Str9,sub(Str1,I,1)) and sub(Str1,I,1)≠":"
:sub(Str1,1,I-1)+sub(Str0,inString(Str9,sub(Str1,I,1)),1)+sub(Str1,I+1,length(Str1)-I)→Str1
:End
:End
:sub(Str1,2,length(Str1)-2)→Str1
:Pause Str1
PROGRAM "StringCase"
VERSION "0.0000"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
s$ = "alphaBETA"
PRINT "Original string: "; s$
PRINT "To Lower case: "; LCASE$(s$)
PRINT "To Upper case: "; UCASE$(s$)
END FUNCTION
END PROGRAM
s$ = "alphaBETA"
print "Original string: ", s$
print "To Lower case: ", lower$(s$)
print "To Upper case: ", upper$(s$)
You may also check:How to resolve the algorithm Hailstone sequence step by step in the CLIPS programming language
You may also check:How to resolve the algorithm Soundex step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Diversity prediction theorem step by step in the C# programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the MoonScript programming language
You may also check:How to resolve the algorithm Fusc sequence step by step in the J programming language