Reversing the given string without using reverse function [closed]

By using Regexes 🙂 var str = “Welcome to the world”; var parts = System.Text.RegularExpressions.Regex.Split(str, ” “); Array.Reverse(parts); var sb = new StringBuilder(); foreach (var part in parts) { sb.Append(part); sb.Append(‘ ‘); } if (sb.Length > 0) { sb.Length–; } var str2 = sb.ToString(); Note that Regex(es) aren’t part of the System.String class 🙂 🙂 … Read more

Indexing every word in a string

You can just split your text on space, removing punctuation along the way, and then iterate through the array and print the indices: String line = “hello, how are you?”; String[] words = line.replaceAll(“[^a-zA-Z ]”, “”).split(“\\s+”); for (int i=0; i < words.length; ++i) { System.out.print(words[i] + “:” + i + ” “); } Explanation: replaceAll(“[^a-zA-Z … Read more

java , inserting between duplicate chars in String [closed]

Well, you could try: Example 1: Using REGEX public static void main(String[] args) { String text = “Hello worlld this is someething cool!”; //add # between all double letters String processingOfText = text.replaceAll(“(\\w)\\1”, “$1#$1”); System.out.println(processingOfText); } Example 2: Using string manipulations public static void main(String[] args) { String text = “Hello worlld this is someething … Read more

What is the equivalent of `string` in C++

The equivalent is std::string or std::wstring declared in the <string> header file. Though you should note that python has probably different intrinsic behavior about handling automatic conversions to UNICODE strings, as mentioned in @Vincent Savard’s comment. To overcome these problems we use additional libraries in c++ like libiconv. It’s available for use on a broad … Read more

find all possible combinations of letters in a string in python [duplicate]

Your example input/output suggests that you are looking for a power set. You could generate a power set for a string using itertools module in Python: from itertools import chain, combinations def powerset(iterable): “powerset([1,2,3]) –> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)” s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) print(list(map(”.join, powerset(‘abcd’)))) … Read more

How to check whether a string contains a substring in JavaScript?

ECMAScript 6 introduced String.prototype.includes: const string = “foo”; const substring = “oo”; console.log(string.includes(substring)); // true includes doesn’t have Internet Explorer support, though. In ECMAScript 5 or older environments, use String.prototype.indexOf, which returns -1 when a substring cannot be found: var string = “foo”; var substring = “oo”; console.log(string.indexOf(substring) !== -1); // true