कंप्यूटर प्रोग्रामिंग/स्ट्रिंग/बेसिक
दिखावट
strings.bas
[सम्पादन | स्रोत सम्पादित करें]' This program splits a given comma-separated name into first and last name
' components and then displays the name.
DECLARE SUB Main()
DECLARE FUNCTION GetName() AS STRING
DECLARE FUNCTION GetLast(FullName AS STRING) AS STRING
DECLARE FUNCTION GetFirst(FullName AS STRING) AS STRING
DECLARE SUB DisplayName(First AS STRING, Last AS STRING)
Main()
SUB Main()
DIM FullName AS STRING
DIM Last AS STRING
DIM First AS STRING
FullName = GetName()
Last = GetLast(FullName)
First = GetFirst(FullName)
DisplayName First, Last
END SUB
FUNCTION GetName() AS STRING
DIM FullName AS STRING
DIM Index AS INTEGER
DO
PRINT "Enter name (last, first):"
LINE INPUT FullName
Index = INSTR(FullName, ",")
LOOP WHILE Index < 1
GetName = FullName
END FUNCTION
FUNCTION GetLast(FullName AS STRING) AS STRING
DIM Index AS INTEGER
Index = INSTR(FullName, ",")
IF Index < 1 THEN
GetLast = ""
ELSE
GetLast = MID$(FullName, 1, Index - 1)
END IF
END FUNCTION
FUNCTION GetFirst(FullName AS STRING) AS STRING
DIM Index AS INTEGER
Index = INSTR(FullName, ",")
IF Index < 1 THEN
GetFirst = ""
ELSE
GetFirst = LTRIM$(MID$(Fullname, Index + 1))
END IF
END FUNCTION
SUB DisplayName(First AS STRING, Last AS STRING)
PRINT "Hello " + First + " " + Last + "!"
END SUB
कोशिश करो
[सम्पादन | स्रोत सम्पादित करें]निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।