string

Can a string literal and a character literal be concatenated?

Why does name misbehave in the following C++ code? string name = "ab"+'c'; How would the equivalent code behave in Java/C#? ...

In C#, why is String a reference type that behaves like a value type?

A String is a reference type even though it has most of the characteristics of a value type such as being immutable and having == overloaded to compare the text rather than making sure they reference the same object. Why isn't string just a value type then? ...

Best way to remove duplicate characters (words) in a string?

What would be the best way of removing any duplicate characters and sets of characters separated by spaces in string? I think this example explains it better: foo = 'h k k h2 h' should become: foo = 'h k h2' # order not important Other example: foo = 's s k' becomes: foo = 's k' etc. ...

Do NSString objects need to be alloc and init?

Noob question: I'm currently under the impression that when you want to create an object, you need to alloc and init that object. However, I've seen seen several sample codes where an NSString object is declared, yet I see no alloc or init messages following... A very simple example: NSString *myString = @"Hello World"; NSLog(@"%@"...

std::stringstream strange behaviour

Some background information, for a homework assignment I had to write a polish notation calculator using binary trees, for this to work I had to parse command line input so that it would properly build the binary tree and then go over it to give a valid answer to the mathematical expression that was entered. For the parsing I used a std...

How can I modify specific part of a binary scalar in Perl?

I adopt select(), sysread(), syswrite() mechanism to handle socket messages where messages are sysread() into $buffer (binary) before they are syswritten. Now I want to change two bytes of the message, which denote the length of the whole message. At first, I use following code: my $msglen=substr($buffer,0,2); # Get the first two byte...

Trying to use String.split() regex on String created with Formatter

Hi All I am a newcomer here, I am using the following code from an open source library (Matrix Toolkits for Java) which outputs the following matrix 1000 1000 5 3 5 1.000000000000e+00 I am trying to do a String split that will return me 1000,1000,5 I tried using String[] parts = str.trim()...

What is the most efficient way in Python to convert a string to all lowercase stripping out all non-ascii alpha characters?

I have a simple task I need to perform in Python, which is to convert a string to all lowercase and strip out all non-ascii non-alpha characters. For example: "This is a Test" -> "thisisatest" "A235th@#$&( er Ra{}|?>ndom" -> "atherrandom" I have a simple function to do this: import string import sys def strip_string_to_lowercase(s...

How to add extra newline with 'puts' without sticking newline character into string?

If I say puts "Hello" and decide to add an extra newline I need to do this: puts "Hello\n" Having this character in the string is ugly. Is there any way to do this without polluting my string? ...

How to convert CFStringRef to NSString?

NSString *aNSString; CFStringRef aCFString; aCFString = CFStringCreateWithCString(NULL, [aNSString UTF8String], NSUTF8StringEncoding); aCFString = CFXMLCreateStringByUnescapingEntities(NULL, aCFString, NULL); How can I get a new NSString from aCFString? ...

Display vs. Search vs. Sort strings in a database

Let's say I've got a database full of music artists. Consider the following artists: The Beatles - "The" is officially part of the name, but we don't want to sort it with the "T"s if we are alphabetizing. We can't easily store it as "Beatles, The" because then we can't search for it properly. Beyoncé - We need to allow the user to be...

Delphi - Problem With Set String and PAnsiChar and Other Strings not Displaying

Hi. I was getting advice from Rob Kennedy and one of his suggestions that greatly increased the speed of an app I was working on was to use SetString and then load it into the VCL component that displayed it. I'm using Delphi 2009 so now that PChar is Unicode, SetString(OutputString, PChar(Output), OutputLength.Value); edtString.Text :...

How to convert strings into integers in python?

Hello there, I have a tuple of tuples from MySQL query like this: T1 = (('13', '17', '18', '21', '32'), ('07', '11', '13', '14', '28'), ('01', '05', '06', '08', '15', '16')) I'd like to convert all the string elements into integers and put it back nicely to list of lists this time: T2 = [[13, 17, 18, 21, 32], [7, 11, 13,...

Delimiter to use within a query string value

I need to accept a list of file names in a query string. ie: http://someSite/someApp/myUtil.ashx?files=file1.txt|file2.bmp|file3.doc Do you have any recommendations on what delimiter to use? ...

Searching for a string 'somewhere' in a database

Here's my problem: I'm looking at someone's Postgresql based database application for the first time and trying to find what is causing certain warnings/errors in the system's logfile. I don't know anything about the database schema. I don't know anything about the source code. But I need to track down the problem. I can easily search f...

Send C++ string to C# string. Interop.

I am new to inter process communication and need some help. I want to be able to send a string from a C++ program to a C# program. My problem is that the resultant string is gibberish. Here is my code: Sending program (C++): void transmitState(char* myStr) { HWND hWnd = ::FindWindow(NULL, _T("myApp v.1.0")); if (hWnd) {...

Fastest way to find most similar string to an input?

Given a query string Q of length N, and a list L of M sequences of length exactly N, what is the most efficient algorithm to find the string in L with the fewest mismatch positions to Q? For example: Q = "ABCDEFG"; L = ["ABCCEFG", "AAAAAAA", "TTAGGGT", "ZYXWVUT"]; answer = L.query(Q); # Returns "ABCCEFG" answer2 = L.query("AAAATAA"); ...

Why can't Python's raw string literals end with a single backslash?

Technically, any odd number of backslashes, as described in the docs. >>> r'\' File "<stdin>", line 1 r'\' ^ SyntaxError: EOL while scanning string literal >>> r'\\' '\\\\' >>> r'\\\' File "<stdin>", line 1 r'\\\' ^ SyntaxError: EOL while scanning string literal It seems like the parser could just treat bac...

How to check if the input string is a valid VB string?

We know that VB string start and end with double quotes " " So we have to use "" if we want " in VB string. I wonder if there is a regular expression pattern which will match VB string?. Thanks. ...

Backslashes in Single quoted strings vs. Double quoted strings in Ruby?

I'm a little confused about when to use single quoted strings versus double quoted strings. I've noticed that if I put a variable inside a single quoted string, it doesn't get interpreted. Also, if I use a newline character in a double quoted string, it causes the string to be displayed over two lines whereas in a single quoted string th...