[Solved] When string.lenght() is 0 throw an exception

Try this out. This should give you Exception. public static void main(String[] args) throws Exception { Scanner keyboard = new Scanner(System.in); System.out.print(“Enter: “); String entry = keyboard.nextLine(); keyboard.close(); if (entry.length() == 0) { throw new Exception(“Exception Found”); } else { String reverse = reverse(entry); if (reverse.length() == 0) { throw new Exception(“Exception Found”); } else … Read more

[Solved] Custom radix columns (+special characters) [closed]

How about using the basic base 10 to any base conversion, modified for custom digits: func numberToCustomRadix(_ number: Int, alphabet: String) -> String { let base = alphabet.count var number = number var result = “” repeat { let idx = alphabet.index(alphabet.startIndex, offsetBy: number % base) result = [alphabet[idx]] + result number /= base } … Read more

[Solved] How to delete part of a string in C++

#include <string> #include <iostream> // std::cout & std::cin using namespace std; int main () { string str (“This is an example phrase.”); string::iterator it; str.erase (10,8); cout << str << endl; // “This is an phrase.” it=str.begin()+9; str.erase (it); cout << str << endl; // “This is a phrase.” str.erase (str.begin()+5, str.end()-7); cout << str … Read more

[Solved] 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

[Solved] I have a Java String, i need to extract only the first digits from it. for example the String: “2 fishes 3” I want to get only: “2”

This should work 🙂 String num1 = mEtfirst.getText().toString(); char[] temp = num1.toCharArray(); int i=0; num1=””; while(Character.isDigit(temp[i])) num1=num1+Character.toString(temp[i++]); This converts the string to a character array, checks the array character by character, and stores it in num1 until a non-digit character is encountered. Edit: Also, if you want to convert num1 to an integer, use: num1=Integer.parseInt(num1); … Read more

[Solved] find and differentiate words in javascript [closed]

If it is about the longest possible matching (sub)string, thus the most specific one, the task actually can be solved pretty easy. sort the array descending by each of its string-item’s length property. Iterate the array … for each string item, try whether it is included within the given text. Stop iterating with the first … Read more

[Solved] How does this code works in c++? [closed]

If the two strings are equal, there is no “uncommon subsequence”. If they are not equal, neither one is a subsequence of the other, but each one is a subsequence of itself, so each one is an “uncommon subsequence”. The longer of the two is the longest “uncommon subsequence”, and its length is the correct … Read more

[Solved] Take second of three numbers from a line in a file [closed]

One thing you could do is extract all numbers, then use the second one: my $astring = “cool more 23423 random words of 1234 random other [wordssssssss] 23”; my @numbers = $astring =~ /[0-9]+/g; print “The second number is $numbers[1]\n”; 1 solved Take second of three numbers from a line in a file [closed]

[Solved] How to replace specific part of a string (replace() dosen’t help…) [closed]

I just got a trick for you to achieving what you want. a = “hello world, hello there, hello python” a = a.replace(“hello”,”hi”,2).replace(“hi”,”hello”,1) print(a) So what exactly 2nd Line does it it is replacing first two occurrence of hello to hi and then replacing 1st occurrence of hi to hello. Thus getting the output you … Read more

[Solved] Extract image URL in a string (RSS with syndicationfeed)

Complete solution with regex : string source =”<img src=\”http://MyUrl.JPG.jpg\””; var reg = new Regex(“src=(?:\”|\’)?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\”|\’)?”); var match=reg.Match(source); if(match.Success) { var encod = match.Groups[“imgSrc”].Value; } solved Extract image URL in a string (RSS with syndicationfeed)

[Solved] I want to count frequency or occurrence of a every letter in a string C program

Ok here is the rewrite, the original code is better but this one might be easier to understand: #include <stdio.h> #include <string.h> int main() { char cur_char; char string[100]; int index = 0, count[255] = {0}; printf(“Enter a string\n”); gets(string); while (string[index] != ‘\0’) { char cur_char = string[index]; // cur_char is a char but … Read more