[Solved] strncmp don’t work as it should

strcmp & strncmp functions return 0 if strings are equal. You should do: if (strncmp(frase1, frase3, 4) == 0) … i.e.: char *str1 = “Example 1”; char *str2 = “Example 2”; char *str3 = “Some string”; char *str4 = “Example 1”; if (strncmp(str1, str2, 7) == 0) printf(“YES\n”); // “Example” <-> “Example” else printf(“NO\n”); if … Read more

[Solved] How to approach this hackerrank puzzle?

I could not post it to comment section. Please see below: List<Integer> integers = Arrays.asList(1, 2, 3, 4); int i = 0; StringBuilder sb = new StringBuilder(“[“); for (int value : integers) { sb.append((i == 0) ? “” : (i % 2 == 0 ? “,” : “:”)).append(value); i++; } sb.append(“]”); System.out.println(sb.toString()); Output is: [1:2,3:4] … Read more

[Solved] C++ Probllem with output [closed]

You should be able to just use string concatenation with +. mfile.open ( accname + “.txt”); If you are not on c++ 11, then you probably need a C-style string. mfile.open ( (accname + “.txt”).c_str()); 5 solved C++ Probllem with output [closed]

[Solved] returning string in C function [closed]

The idea is not that bad, the main errors are the mix-up of numerical digits and characters as shown in the comments. Also: if you use dynamic memory, than use dynamic memory. If you only want to use a fixed small amount you should use the stack instead, e.g.: c[100], but that came up in … Read more

[Solved] string type in python language [closed]

Python strings are immutable. Any operation that appears to be changing a string’s length is actually returning a new string. Definately not your third option — a string can start out arbitrary long but can’t later change it’s length. Your option 1 sounds closest. You may find the Strings subsection of this web page helpful. … Read more

[Solved] Find String in ArrayList Containing Phrase

public static void main(String[] args) { List<String> data = new ArrayList<String>(); String yourRequiredString = “dessert”; data.add(“apple fruit”); data.add(“carrot vegetable”); data.add(“cake dessert”); for (int i = 0; i < data.size(); i++) { if (data.get(i).contains(yourRequiredString)) { System.out.println(i); } } } Hope this helps… solved Find String in ArrayList Containing Phrase

[Solved] Need the words between the ” – ” ONLY string splitting [duplicate]

So basically you to first split by – and then each side by a non-word character. Therefore you can try: String s = “ABC_DEF-HIJ (KL MNOP_QRS)”; String[] splits = s.split(“-“); // {“ABC_DEF”, “HIJ (KL MNOP_QRS)”} String[] lefts = split[0].split(“[^a-zA-Z]”); // {“ABC”, “DEF”} String[] rights = split[1].split(“[^a-zA-Z]”); // {“HIJ”, “”, “KL”, “MNOP”, “QRS”} String string1 = … Read more