Creating a comma separated list from IList or IEnumerable

.NET 4+ IList<string> strings = new List<string>{“1″,”2″,”testing”}; string joined = string.Join(“,”, strings); Detail & Pre .Net 4.0 Solutions IEnumerable<string> can be converted into a string array very easily with LINQ (.NET 3.5): IEnumerable<string> strings = …; string[] array = strings.ToArray(); It’s easy enough to write the equivalent helper method if you need to: public static … Read more

How do I check if string contains substring? [duplicate]

Like this: if (str.indexOf(“Yes”) >= 0) …or you can use the tilde operator: if (~str.indexOf(“Yes”)) This works because indexOf() returns -1 if the string wasn’t found at all. Note that this is case-sensitive. If you want a case-insensitive search, you can write if (str.toLowerCase().indexOf(“yes”) >= 0) Or: if (/yes/i.test(str)) The latter is a regular expression … Read more

Using strtok() in nested loops in C?

Yes, strtok(), indeed, uses some static memory to save its context between invocations. Use a reentrant version of strtok(), strtok_r() instead, or strtok_s() if you are using VS (identical to strtok_r()). It has an additional context argument, and you can use different contexts in different loops. char *tok, *saved; for (tok = strtok_r(str, “%”, &saved); … Read more

how to convert csv to table in oracle

The following works invoke it as select * from table(splitter(‘a,b,c,d’)) create or replace function splitter(p_str in varchar2) return sys.odcivarchar2list is v_tab sys.odcivarchar2list:=new sys.odcivarchar2list(); begin with cte as (select level ind from dual connect by level <=regexp_count(p_str,’,’) +1 ) select regexp_substr(p_str,'[^,]+’,1,ind) bulk collect into v_tab from cte; return v_tab; end; /

How to split a string into substrings of a given length? [duplicate]

Here is one way substring(“aabbccccdd”, seq(1, 9, 2), seq(2, 10, 2)) #[1] “aa” “bb” “cc” “cc” “dd” or more generally text <- “aabbccccdd” substring(text, seq(1, nchar(text)-1, 2), seq(2, nchar(text), 2)) #[1] “aa” “bb” “cc” “cc” “dd” Edit: This is much, much faster sst <- strsplit(text, “”)[[1]] out <- paste0(sst[c(TRUE, FALSE)], sst[c(FALSE, TRUE)]) It first splits … Read more

String comparison – Android [duplicate]

Try this if(gender.equals(“Male”)) salutation =”Mr.”; if(gender.equals(“Female”)) salutation =”Ms.”; Also remove ;(semi-colon ) in your if statement if(gender.equals(g1)); In Java, one of the most common mistakes newcomers meet is using == to compare Strings. You have to remember, == compares the object references, not the content.

python replace single backslash with double backslash

No need to use str.replace or string.replace here, just convert that string to a raw string: >>> strs = r”C:\Users\Josh\Desktop\20130216″ ^ | notice the ‘r’ Below is the repr version of the above string, that’s why you’re seeing \\ here. But, in fact the actual string contains just ‘\’ not \\. >>> strs ‘C:\\Users\\Josh\\Desktop\\20130216’ >>> … Read more