string

Most elegant way to detect if a String is a number?

Is there a better, more elegant (and/or possibly faster) way than boolean isNumber = false; try{ Double.valueOf(myNumber); isNumber = true; } catch (NumberFormatException e) { } ...? Edit: Since I can't pick two answers I'm going with the regex one because a) it's elegant and b) saying "Jon Skeet solved the problem" is a tau...

Ignoring accented letters in string comparison

I need to compare 2 strings in C# and treat accented letters the same as non-accented letters. For example: string s1 = "hello"; string s2 = "héllo"; s1.Equals(s2, StringComparison.InvariantCultureIgnoreCase); s1.Equals(s2, StringComparison.OrdinalIgnoreCase); These 2 strings need to be the same (as far as my application is concerned...

initializing std::string from char* without copy

I have a situation where I need to process large (many GB's) amounts of data as such: build a large string by appending many smaller (C char*) strings trim the string convert the string into a C++ const std::string for processing (read only) repeat The data in each iteration are independent. My question is, I'd like to minimise (if ...

SubString function in vb.net throwing Exception

FromIp contains "192.168.1.1". I want to get the last number, but I can't figure out what's wrong here: Dim str As String str = FromIP.Text.Substring(FromIP.Text.LastIndexOf("."), FromIP.Text.Length).ToString() MessageBox.Show(FromIP.Text.Length) ...

variable or field declared void

Hello I am working in c++: I have a function called: void initializeJSP(string Experiment) And in my MyJSP.h file I have: 2: void initializeJSP(string Experiment); And when I compile I get this error: MyJSP.h:2 error: variable or field initializeJSP declared void, the error is Where is the problem?. Thank you. ...

Splitting a string into words and punctuation

I'm trying to split a string up into words and punctuation, adding the punctuation to the list produced by the split. For instance: >>> c = "help, me" >>> print c.split() ['help,', 'me'] What I really want the list to look like is: ['help', ',', 'me'] So, I want the string split at whitespace with the punctuation split from the wo...

String extraction.

Hey guys. Currently I am working very basic game using the C++ environment. The game used to be a school project but now that I am done with that programming class, I wanted to expand my skills and put some more flourish on this old assignment. I have already made a lot of changes that I am pleased with. I have centralized all the dat...

Comma "izing" a list of items

Given a list of strings, what is the best method for concatenating these strings into a comma separated list with no comma at the end. (VB.NET or C#) (Using either StringBuilder or String Concat.) Dim strResult As String = "" Dim lstItems As New List(Of String) lstItems.Add("Hello") lstItems.Add("World") For Each strItem As String In ls...

PHP get rid of slashes full path

Hey everyone, I have a full path which I would like to remove certain levels of it. So for instance, /home/john/smith/web/test/testing/nothing/ I would like to get rid of 4 levels, so I get /test/testing/nothing/ What would be a good of doing this? Thanks ...

How do I convert C# characters to their hexadecimal code representation.

What I need to do is convert a C# character to an escaped unicode string: So, 'A' - > "\x0041". Is there a better way to do this than: char ch = 'A'; string strOut = String.Format("\\x{0}", Convert.ToUInt16(ch).ToString("x4")); ...

How do I do a fuzzy match of company names in MYSQL with PHP for auto-complete?

My users will import through cut and paste a large string that will contain company names. I have an existing and growing MYSQL database of companies names, each with a unique company_id. I want to be able to parse through the string and assign to each of the user-inputed company names a fuzzy match. Right now, just doing a straight-...

How to trim whitespace from bash variable?

I have a shell script with this code: var=`hg st -R "$path"` if [ -n "$var" ]; then echo $var fi But the conditional code always executes because hg st always prints at least one newline character. Is there a simple way to strip whitespace from $var (like trim() in php)? or Is there a standard way of dealing with this issue?...

Simple properties to string conversion in Java

Using Java, I need to encode a Map<String, String> of name value pairs to store into a String, and be able to decode it again. These will be stored in a database column, and will probably usually be short and simple, so the common case should produce a simple nice looking line, but shouldn't corrupt the data, even if it contains unexpe...

Remove character from string if it starts with that character?

How can I remove the very first "1" from any string if that string starts with a "1"? "1hello world" => "hello world" "112345" => "12345" I'm thinking of doing string.sub!('1', '') if string =~ /^1/ but I' wondering there's a better way. Thanks! ...

Simplest way of mapping an index to a string in C++

Requirements: Must be able to use C strings as well as C++ strings Fast No maps No templates No direct lookup, i.e. index might be out of bounds. Index is not consecutive Enums and strings contained in one header file Only instantiate what you use. This is what I have come up with so far: - test.hh - // Generic mapper // // The id...

How do I write a string search query that uses the non-clustered indexing I have in place on the field?

I'm looking to build a query that will use the non-clustered indexing plan on a street address field that is built with a non-clustered index. The problem I'm having is that if I'm searching for a street address I will most likely be using the 'like' eval function. I'm thinking that using this function will cause a table scan instead o...

Oracle SQL - Parsing a name string and converting it to first initial & last name

Hey.. Does anyone know how to turn this string: "Smith, John R" Into this string: "jsmith" ? I need to lowercase everything with lower() Find where the comma is and track it's integer location value Get the first character after that comma and put it in front of the string Then get the entire last name and stick it after the first init...

String Immutability

Does string immutability work by statement, or by strings within a statement? For example, I understand that the following code will allocate two strings on the heap. string s = "hello "; s += "world!"; "hello" will remain on the heap until garbage collected; and s now references "hello world!" on the heap. However, how many strings...

split string on a number of different characters

I'd like to split a string using one or more separator characters. E.g. "a b.c", split on " " and "." would give the list ["a", "b", "c"]. At the moment, I can't see anything in the standard library to do this, and my own attempts are a bit clumsy. E.g. def my_split(string, split_chars): if isinstance(string_L, basestring): ...

Is char* supported on Chinese / Japanese machines?

Hi, I am trying to create a DLL for authentication using Java and JNI. To create the DLL, I have created a Win32 application whose Character Set and Runtime Library information are Multi-Byte String and Multi-threaded (/MT) respectively. I have tested the DLL on WinXP with valid and invalid user credentials. Both work fine. I need t...