How to obtain Uppercase string from a sentence in clojure? [closed] - string

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am new to clojure and not well versed with the available functions. So I wanted to know how to retrieve uppercase words from a sentence.
For Example:
Input: IllegalArgumentException contains? not SUPPORTED on type: java.lang.String clojure.lang.RT.contains
Output: SUPPORTED

One way would be to use regular expression like in any other language:
(re-find #"\b[A-Z]+\b" s)
;; => "SUPPORTED"
If there's more than one expected match, you can use re-seq:
(re-seq #"\b[A-Z]+\b" "THIS is a TEST")
;; => ("THIS" "TEST")
Since you mentioned you're not well-versed with regards to available functions, please check out ClojureDocs.

First we write a function that tests whether a string is upper-case or not.
(defn upper-case? [word]
(= word (clojure.string/upper-case word)))
Then we split any string into words and filter out all words that are not upper-case. In your example there was at least one instance of two consecutive spaces, so those had to be filtered out as well.
(defn upper-case-words [sentence]
(filterv #(and (upper-case? %) (not= "" %)) (clojure.string/split sentence #" ")))
(upper-case-words "Input: IllegalArgumentException contains? not SUPPORTED on type: java.lang.String clojure.lang.RT.contains")
["SUPPORTED"]

Related

How to find the number of common characters of two input strings in Assembly? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to compare two input strings and display the number of common characters in Assembly but i can't find how to do that.
To do it efficiently you would need some sort of data structure to remember which characters you have seen already.
If you don’t mind duplicates and don't need efficiency, you could loop over the first string and, for each character, loop over the second string and compare them (adding one to a register or a variable when they match).

Counting character in string in Haskell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
string = "this is an example string"
in haskell, how can i count how many times the character 'a' appears in the string above? Preferably in one line.
Think about it this way: you want to know the size of the list in which all letters that are not 'a' have been removed. To remove these, we can use filter. This function filters out any items in a list that do not satisfy a given predicate. Then getting the size of this list is trivial with length.
length $ filter (\x -> x=='a') "this is an example string"
Edit:
As per AndrewC's suggestion, you can also write this as:
length $ filter (=='a') "this is an example string"
This way is more readable and clearer.

insert letter before vowel in word [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
how to insert letter before vowel in each word in python. like Gibberish game. We have to ask user to to input some letter and input their word to insert some letter that they input at first to before vowels in each word they input at second.
If this is for homework, you really should try to figure this out on your own rather than going to StackOverflow, but you can use regex to do it in one line:
import re
re.sub(r"([aeiou])",r"X\g<1>", "hello")
Or if you want a function version of it:
import re
def add_letter_to_vowels(word, letter):
return re.sub(r"([aeiou])",r"%s\g<1>"%letter, word)
Then it runs as follows:
>>> add_letter_to_vowels("hello", "X")
'hXellXo'
Regular expressions are very powerful, read more about them here and the API reference is here

Polish dictionary database - weird symbols (subst:sg:voc:f) - what are they? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
As in the title, I am working with database containing a Polish dictionary where one of the columns contains records such as:
subst:sg:voc:f
subst:pl:nom.voc:m1
subst:sg:dat:m3
What are those tags? What are they called? How do I read them?
Not knowing anything else about the dictionary (nor polish) they appear to be:
type of word (substantive, verb, adjective, etc)
number (sg: singular, pl: plural)
decliantion (voc: vocative, dat: dative)
gender and person (f: feminine, m1: masculine first person, m3: masculine third person)

2 Simultaneous type renamings in Haskell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
we've been given the task to make a Dictionary, as a List of tuples with (String, String).
The problem here is that I actually have no idea if I can rename String twice at the same time, since I want the tuple to look like this
(German, English)
Is it even possible to just make it look like this?
type German = String
type English = String
type Dictionary = [(German, English)]
Or would there be any conflicts?
It was kinda frustrating not finding a single entry about this, been almost 2 hours and not a single line of code stands right now :|
Yes, you can do that. You can't do the opposite
type German = String
type German = Int -- conflicts here!
Of course you can, if you couldn't, you wouldn't be able to compile type German = String in the first place, as it's already been named ;-)

Resources