|
I have a variable that can either contain a list of strings or a just a string. Is there a good way to tell what kind I'm dealing with?
"192.168.1.18" vs. ["192.168.1.18", "192.168.1.19"]
In either case I want to use the bits involved.
Started by Fylke on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
An alternative would be when generating this string/list of strings to always put.
Or if you are not interested in actually pulling apart the string/list of strings you could do:
if is_list earlier.
|
|
Question I would like to be able to use a single regex (if possible) to require that a string fits [A-Za-z0-9_] but doesn't allow:
Strings containing just numbers or/and symbols. Strings starting or ending with symbols Multiple symbols next to eachother...
Started by epochwolf on
, 10 posts
by 10 people.
Answer Snippets (Read the full thread at stackoverflow):
Look ahead to make sure there's at least one letter in the string, then start consuming input.
|
|
What is the most suitable container just for strings holding in some array with non-predetermined upper boundary, which length is unknown on it's creation.
For simple code like:
Foo list = new Foo(); // size in unknown for()/foreach()/do()/while() // ...
Started by abatishchev on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The Collection<T> class is just.
A StringCollection is just a type safe ( Find , Sort , etc)
A List<T> would be the most efficient.
Have to cast the items to String when reading from it.
|
Ask your Facebook Friends
|
Which is more efficient for the compiler and the best practice for checking whether a string is blank?
Checking whether the length of the string == 0 Checking whether the string is empty (strVar == "") Also, does the answer depend on language?
Started by Haydar on
, 13 posts
by 12 people.
Answer Snippets (Read the full thread at stackoverflow):
Pascal-type strings the best way to determine....
You basically just pay for an extra functionYes, it depends on language, since string storage differs between languages.
Checking the first character in the string are both O(1).
|
|
Can someone explain to me why ServletRequest.getParameterMap() returns type
Map<String, String[]>
ServletRequest.getParameter() just returns type String
I'm don't understand why the map would ever map to more then one value. TIA.
Started by BillMan on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Opel</option> </select>
Any checked/selected values will come in as:
String[] cars parameter values is
request.getParameterValues();
getParameter() is just a shortcut to get first one..
|
|
Ended up with this awful data structure:
List<KeyValuePair<string, KeyValuePair<string, string>>>
It's not likely to get huge (<1K I estimate) and I am gonna iterate this list over and over.
Anyone can think of some better alternative...
Started by JohnIdol on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Tuple<string,string,string>>
This is easy enough to write in .NET 2.0 - it's basically juststruct MrStruct { public string Key1, public string Key2, public string Value1 } List< dramatically speed up any ....
|
|
I work with different servers and configurations. What is the best java code approach for getting the scheme://host:[port if it is not port 80].
Here is some code I have used, but don't know if this is the best approach. (this is pseudo code)
HttpServletRequest...
Started by Berlin Brown on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
(That's the one you want.) Group 2 contains....
URI u=new URI("http://www.google.com/"); String s(), request.getServerName(), port, "");
public String getServer(HttpServletRequest request) { int port.
I think java.net.URI does what you want.
|
|
Possible Duplicates:
In C# what is the difference between String and string
String vs string in C#
what is difference between String and string(data type) in c# asp.net?
Started by Domnic on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The first is just.
There's no difference.
string is an alias.
System.String is the datatype.
|
|
I need a MySQL query w/ Regex to tell me if my string's first character is a number from 0 to 9.
Started by phirschybar on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You can adapt it for your purposes:
SELECT '123 this starts with a digit' REGEXP '^[[:digit:]]';
You can use it in a SELECT like this:
SELECT * FROM tbl WHERE field REGEXP '^[[:digit:]]';
SELECT... .
The following query returns '1', since the REGEXP matches.
|
|
I am using the Microsoft.Practices.EnterpriseLibrary Database tools and I'm having trouble creating a new database using just the connection string information.
Ideally I would like to do the following:
Database dbEngine = DatabaseFactory.CreateDatabase...
Started by Scott Vercuski on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I discovered that you can use the following as the Database object but it works for ... .
That's because CreateDatabase expects the name of a connection string (as specified in your app's config file), not the connection string itself.
|