Get name of lambda function as string in Ruby

I have a defined a lambda function as my_lambda = lambda { |x| 100 * x } I am passing this function as an input to another function which needs to verify its identify, something like: def function_verifier(func) if func.to_s == "my_lambda" ...
more »

2017-10-03 21:10 (1) Answers

SML function that takes a filename and a list

I want to write a function that takes a filename as a string and a list of pairs of characters. This function must open the named file, read the contents of the file, and echo the characters to the screen. Any occurrence of a character in the first p...
more »

2017-10-03 08:10 (1) Answers

How to remove spaces from a string in Swift?

I have the need to remove leading and trailing spaces around a punctuation character. For example: Hello , World ... I 'm a newbie iOS Developer. And I'd like to have: > Hello, World... I'm a newbie iOS Developer. How can I do this? I tried to ge...
more »

2017-10-02 22:10 (6) Answers

How to check Validity of an URL

I am working on a web Browser, I have a SearchView in it, for user to input queries. I want to differentiate between a search query or a web address. My current code just add http://www. in front of any query that comes in and try to load it. This i...
more »

2017-10-02 19:10 (3) Answers

How I can delete words if word have this letters

I must delete words if in word have letters "ц", "щ", "ы", "ь". I create this functions for need me but it works slow. public function CheckToInsert($text) { $xarfho = array("ц", "щ", "ы", "ь","қ","ӣ","ғ","ҷ","ҳ","ӯ","Қ","Ӣ","Ғ","...
more »

2017-10-02 13:10 (2) Answers

String Validation

How do you validate a string to check if it has only uppercase letters? And how do you check if it has both uppercase and lowercase letters? cout << "Enter state name or state abbr:" << " " << endl; cin >> st; if ((st == sta...
more »

2017-10-02 09:10 (1) Answers

Java: Find String with the highest value

I need to accept a string as input, split it into an array of individual words ( split on " ") and return the highest scoring word as a string. Each letter of a word scores points according to it's position in the alphabet: a = 1, b = 2, c = 3 etc. I...
more »

2017-10-02 05:10 (5) Answers

if==True;but built-in functions doesn't run

f <- readLines('/home/dogus/Desktop/phonezzzz/vcards.txt', encoding="UTF-8") #empty lists names <- c() numbers <- c() phonezz <- function(){ for(i in 1:length(f)){ if("FN" == substring(f[i],0,2)){ name <- substring(f[i],4...
more »

2017-10-01 22:10 (2) Answers

How to perform bincount on an array of strings?

I have NumPy array containing string values. For instance: ["bus", "bar", "bar", "café" .....] What is the best way of counting the number of occurrences of each element in my array. My current solution is: # my_list contains my data. bincou...
more »

2017-09-30 15:09 (2) Answers

Ruby to_s a special method?

I'm working on Ruby Koans about_to_str.rb. I've gotten it to work but some code I don't understand. I'm confused why the CanNotBeTreatedAsString classes to_s produces different results than the CanBeTreatedAsString to_s Both tests test_to_str_allows...
more »

2017-09-25 07:09 (0) Answers

Storing string input into different arrays in C

Hello this brand new noob on C is trying to take a string input of 3 words and store it on 3 different arrays, not 2D nor 3D arrays. For this problem I'm not allow to use any of the string library functions. Basically I'm trying to implement the ssca...
more »

2017-09-24 22:09 (2) Answers

C++ class member behaving as local variable

I have just started programming in C++, and I have found an awkward issue. Basically: I have one class where a member is a char[MAX_LEN] containing the full path of a file. I have one (char*) that points to the name (without the full path) of the ...
more »

2017-09-23 16:09 (2) Answers

Oracle SQL - find string pattern in string

I need to extract some text from a string, but only where the text matches a string pattern. The string pattern will consist of... 2 numbers, a forward slash and 6 numbers e.g. 12/123456 or 2 numbers, a forward slash, 6 numbers, a hyphen and 2 num...
more »

2017-09-22 18:09 (3) Answers

Indexing with [Int] and [[String]] Haskell

I have in index [Int] and [[String]], now I only want to keep the [String] which correspond to the index: [0,1,4] and [[a,a,a],[b,b,b],[c,c,c],[d,d,d],[e,e,e],[f,f,f]] would give [[a,a,a],[b,b,b],[e,e,e]] So [Int] -> [[String]] -> [[String]]...
more »

2017-09-22 15:09 (2) Answers

Haskell: checking the vowels in a String

I'm new to Haskell. I wanted to write a code, which checks if there is any vowel in a String. I came up with this solution: n :: Int n = 0 vowel :: String -> Bool vowel a | check n = a !! n | check == 'a' || 'e' || 'i' || 'o' || 'u' |...
more »

2017-09-22 14:09 (4) Answers

String to List of Int

I would like to incorporate Maybe [int] into this. The code should take a string and filter out spaces turning it into a list of integers and if their are letters return Nothing. text2digits :: String -> [Int] text2digits s = case s of [] ...
more »

2017-09-22 07:09 (1) Answers

Comparing two strings in Haskell

I came across a rather silly practice problem that was listed as easy, so I thought I could do it. The premise is that a doctor must hear a patient say aah in order to give a diagnosis, but the aah from the patient must match the aah requested by th...
more »

2017-09-20 19:09 (1) Answers

pattern matching for strings

func swtiching (a: String, b: String){ switch (a,b){ case ("a", "b"): print("a and b") case (("a" || "c"), ("b" || "d")): print(" a or b and c or d") default: print("something else") } } If I do this, the 2nd case will give the...
more »

2017-09-19 22:09 (2) Answers