|
In Java, how do I convert an array of strings to a array of unique values?
If I have this array of Strings:
String[] test = {"1","1","1","2"}
And I want to end up with:
String[] uq = {"1","2"}
Started by djangofan on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
List list = Arrays.asList(test); Set set = new HashSet(list); String[] uq = set.toArrayAn easy way is to create a set, add each element in the array to it, and then convert the set;(Arrays.asList(test)); String....
To an array.
|
|
I have SQL Server 2005 Report that takes a parameter in a query string that searches customer names. The problem is some customers like to put in a middle initial so when the user 'John Smith' this does not bring up 'John Q. Smith'.
Using only sql, how...
Started by x13 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You can use a user-defined split function, like the one here and use that something like this:
SELECT * FROM SomeTable t WHERE NOT EXISTS (SELECT * FROM dbo.Split('John Smith', ' ') s WHERE t.NameColumn NOT LIKE '%' + s.Data + '%')
You'd need to see how... .
|
|
I have two arrays of Strings, for example sentences and words. If any word is found in a sentence e.g. sentence =~ /#{word}/ I want to reject the sentence from the sentence array. This is easy to do with a double loop, but I'm wondering if there is a ...
Started by Matt on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Sentence =~ /word1|word....
So, the word cat would knock out the sentence: String by the "|" character.
Array subtraction is your friend here:
words.each do |word| sentences -= sentences.grep(/#{word whitespace separated words in the sentence.
|
Ask your Facebook Friends
|
Hi all,
I'm a beginner in C++ Programming language. I wanted to write a program that take the alphabets in a string array called str, and copy it in a new array called str_alpha.
And the same goes to numbers, the program copies it from str array to str...
Started by rafael on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Use plain assignment (= operator) for copying is that strcpy is... .
Strcpy copies a whole string.
No function call needed.
Types for this, in your case string :
string str; cin >> str; string alpha; string digit.
|
|
If you had an array of Strings, what is the quickest way to sort this array in ascending order ?
Started by Johanna on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
String[] Mystring = {"cat","lion", "dog", "mouse"}; Arrays.sort(Mystring);
Sorting Arrays.
|
|
I have an array of Tag objects
class Tag { public string Name; public string Parent; }
i want code to return a list of the tag names as an array of strings
Started by oo on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Return (from Tag in MyTagArray select Tag.Name).ToArray();
string[] tagArray = (from t in tagList select t.Name).ToArray();
I assume that you, and if you need an array, call....
Names, just use .ToArray() if you wan't array of those.
|
|
What is the fastest way to compare a string with an array of strings in C#2.0
Started by Greens on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Will return a boolean value indicating....
Exists = Array.IndexOf(array, input) >= 0;
You mean to see if the string is in the array? I can't array to the list via AddRange(), then call list.Contains({string to compare}).
|
|
I have a small problem here.I need to convert a string read from console into each character of string. For example string: "aabbab" I want to this string into array of string.How would I do that?
Started by gingergeek on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
*/ String str = "one-two....
If by array of String you mean array of char:
public class Test { public static void main(String into an array of String
See those String.split examples
/* String to split.
|
|
Is there an easy way to convert a string array into a concantenated string?
For example, I have a string array:
new string[]{"Apples", "Bananas", "Cherries"};
And I want to get a single string:
"Apples,Bananas,Cherries"
Or "Apples&Bananas&Cherries" or...
Started by Moose Factory on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
string[] theArray = new string[]{"Apples", "Bananas", "Cherries"}; string s = string.Join(",",theArray);
String.Join Method (String, String[])
The obvious choise is of course.
A simple one...
|
|
Private string[] ColeccionDeCortes(string Path) { DirectoryInfo X = new DirectoryInfo(Path); FileInfo[] listaDeArchivos = X.GetFiles(); string[] Coleccion; foreach (FileInfo FI in listaDeArchivos) { //Add the FI.Name to the Coleccion[] array, } return...
Started by John McClane on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Edit: If you ....
Using;string>(); … myCollection.Add(aString);
If you really want an array at the end, use returning the collection.
Instead I would use a StringCollection.
] = "new string";
I would not use an array in this case.
|