[Solved] Using String#contains() and String#indexOf() to locate a date format String in a comma separated list finds incorrect matches [closed]

Currently you are not searching for a single date format in a list of date formats, you are searching for a date format String within a single String that contains multiple comma separated date formats. Since that String starts with “dd/MM/yyyy”, which contains “dd/MM/yy”, both contains and indexOf find a match (which, given your requirements, … Read more

[Solved] Add a string to an ArrayList

If you are declaring list as ArrayList data = new ArrayList(); then you get the message about parameterizing the list because data can hold any Object If you know that you are going to add only strings in your list, declare it as ArrayList<String> data = new ArrayList<String>(); // pre java 7 ArrayList<String> data = … Read more

[Solved] Splitting a string ignoring whitespace

We’ll need to see your code before we can begin troubleshooting. However, the following code should work just fine: String address = “1,1,87 gandhi road,600005”; String[] stringArray = address.split(“,”); for(String str : stringArray) { // Do something with str. } 5 solved Splitting a string ignoring whitespace

[Solved] App is crashing when I convert string to int

check if its not null then cast to integer: try { if(description[i][j]!=null && description[i][j].length()>0){ id=Integer.parseInt(description[i][j]); Toast.makeText(getApplicationContext(),id, Toast.LENGTH_SHORT).show(); } } instead of try { id=Integer.parseInt(description[i][j]); } i hope its work but description[i][j] must returns string. if id getting value then print toast.otherwise no toast print.. 2 solved App is crashing when I convert string to int

[Solved] C++ How to fill a char* array of strings with new values using c_str() on top of old ones [duplicate]

I try to copy the string into the array of string literals What you are trying to do isn’t legal C++. char* MapIds[5000] = … should be const char* MapIds[5000] = … and trying to overwrite anything in that array makes your program have undefined behavior. I try to stay away from std::string and instead … Read more

[Solved] A dictionary that returns number of word and each word’s lenght Python

sample = “i am feeling good” output = {} output[“word”] = len(sample.split()) output[“chars”] = len(list(sample)) for elem in sample.split(): output[elem] = len(list(elem)) print(output) output: {‘word’: 4, ‘chars’: 17, ‘i’: 1, ‘am’: 2, ‘feeling’: 7, ‘good’: 4} solved A dictionary that returns number of word and each word’s lenght Python

[Solved] This if statement is not even working correctly

This is a problem with your indentation. You can learn about indentation here: https://docs.python.org/2.0/ref/indentation.html and on the web. To get your code working do the following: string = “A” secret_word = “Apple” if string in secret_word: print(“Good!”) else: print(“Bad…”) 4 solved This if statement is not even working correctly

[Solved] how can i print this using String Methods

Thanks for all answers by you. I got my answer for my question as i was trying.. sorry for uploading it late but got so many other ways to do it. Here is my answer. String res = “”; public String altPairs(String str) { int i=0; while (i<str.length()) { res +=str.charAt(i); i=i+1; if(i<str.length()) { res+=str.charAt(i); … Read more

[Solved] How to check in Java whether the input Sentence is of palindrome(not exactly, but like that) in nature or not?

First take the words of str in an array. Then check whether the words in the forward order and the reverse order are same. String[] words = str.split(” “); //splits at spaces boolean flag = true; int i, last = words.length – 1; for(i = 0; i <= last/2; i++){ if(!words[i].equalsIgnoreCase(words[last – i])){ flag = … Read more

[Solved] why the following code gives the first mobile no. irrespective of name

You cannot compare strings using = (or even by ==, for that matter) operator. You need to use strcmp() for that. In your code, inside mobileno() function, if( s=”katrina” ) is essentially trying to assign the base address of the string literal “katrina” to s. It is nowhere near a comparison. That said, Never use … Read more

[Solved] Convert string to rubbish

If you want a function that will return the same garbage for the same input string, this would work fine. public String rubbish(String input) { String result = “”; long seed = 0; long size = 0; for(int i = 0; i < input.length(); i ++) { seed += input.charAt(i); } seed %= Long.MAX_VALUE; size … Read more

[Solved] How to print string backward in C++? [closed]

Your initial array index points to \0, you need something like – for(int i=size-1; i>=0; i–) // <– like this or for(int i=size; i>0; i–) { cout<<input[i-1]; // <– like this } or you could use reverse #include <algorithm> // <– add this include std::reverse(input.begin(), input.end()); // <– reverse the input string. 6 solved How … Read more