Determine sentence type: Difference between revisions

add FreeBASIC
(add FreeBASIC)
Line 163:
Are you sure?!?! How can you know? -> EQ|Q
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>function sentype( byref s as string ) as string
'determines the sentence type of the first sentence in the string
'returns "E" for an exclamation, "Q" for a question, "S" for serious
'and "N" for neutral.
'modifies the string to remove the first sentence
for i as uinteger = 1 to len(s)
if mid(s, i, 1) = "!" then
s=right(s,len(s)-i)
return "E"
end if
if mid(s, i, 1) = "." then
s=right(s,len(s)-i)
return "S"
end if
if mid(s, i, 1) = "?" then
s=right(s,len(s)-i)
return "Q"
end if
next i
'if we get to the end without encountering punctuation, this
'must be a neutral sentence, which can only happen as the last one
s=""
return "N"
end function
 
dim as string spam = "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! Just make sure you don't break it"
 
while len(spam)>0
print sentype(spam)
wend</lang>
{{out}}<pre>Q
S
E
N
</pre>
 
 
=={{header|Go}}==
781

edits