string

What is the difference between String.Empty and ""

In .NET, what is the difference between String.Empty and "", and are they interchangable, or is there some underlying reference or Localization issues around equality that String.Empty will ensure are not a problem? ...

How to Conditionally Format a String in .Net?

I would like to do some condition formatting of strings. I know that you can do some conditional formatting of integers and floats as follows: Int32 i = 0; i.ToString("$#,##0.00;($#,##0.00);Zero"); The above code would result in one of three formats if the variable is positive, negative, or zero. I would like to know if there is any...

Convert JavaScript String to be all lower case?

How can I convert a JavaScript string value to be in all lower case letters? Example: "Your Name" to "your name". ...

Marshal C++ "string" class in C# P/Invoke

I have a function in a native DLL defined as follows: #include <string> void SetPath(string path); I tried to put this in Microsoft's P/Invoke Interop Assistant, but it chokes on the "string" class (which I think is from MFC?). I have tried marshaling it as a variety of different types (C# String, char[], byte[]) but every time I eit...

Extract all string from a java project

I have a rather big number of source files that I need parse and extract all string literals and put them in a file as play old java constant. For exemple: Label l = new Label("Cat"); Would become: Label l = new Label(Constants.CAT); And in Constants.java I would have: public final static String CAT = "Cat"; I do not want the strin...

How do you put { and } in a format string

I'm trying to generate some code at runtime where I put in some boiler-plate stuff and the user is allowed to enter the actual working code. My boiler-plate code looks something like this: using System; public class ClassName { public double TheFunction(double input) { // user entered code here } } Ideally, I thi...

Using Quotes within getRuntime().exec

Hi, I'd like to invoke bash using a string as input. Something like: sh -l -c "./foo" I'd like to do this from Java. Unfortunately, when I try to invoke the command using getRuntime().exec, I get the following error: foo": -c: line 0: unexpected EOF while looking for matching `"' foo": -c: line 1: syntax error: unexp...

Getting Input C++

Hello, I want to get input from an amount of integers,but after it get input to a string with getline(cin,stringname); But the enter that the user gives when he input numbers to the ints,gets into the string and it doesn't get any input(sentence) to the string,only the "enter" key. how can I solve that? Thanks. ...

Serialization of a long array (in C)

Hi, in a C program I have an long* that I want to serialize (thus converting to chars). A long doesn't fit in a single char, and the size varies depending of the processor (can be 4 bytes or 8 bytes). Theres a good way to make the serialization and de-serialization? ...

Searching For String Literals

In the quest for localization I need to find all the string literals littered amongst our source code. I was looking for a way to script this into a post-modification source repository check. (I.E. after some one checks something in have a box setup to check this stat) I'll probably use NAnt and CruiseControl or something to handle the m...

Escaping a String from getting regex parsed in Java

In Java, suppose I have a String variable S, and I want to search for it inside of another String T, like so: if (T.matches(S)) ... (note: the above line was T.contains() until a few posts pointed out that that method does not use regexes. My bad.) But now suppose S may have unsavory characters in it. For instance, let S = "[hi"...

unexpected T_CONCAT_EQUAL

Hi All, I'm getting an unexpected T_CONCAT_EQUAL error on a line of the following form: $arg1 .= "arg2".$arg3."arg4"; I'm using PHP5. I could simply go an do the following: $arg1 = $arg1."arg2".$arg3."arg4"; but I'd like to know whats going wrong in the first place. Any ideas? Thanks, sweeney ...

strcat() new line, duplicate string

I'm writing a function that gets the path environment variable of a system, splits up each path, then concats on some other extra characters onto the end of each path. Everything works fine until I use the strcat() function (see code below). char* prependPath( char* exeName ) { char* path = getenv("PATH"); char* pathDeepCopy ...

How do I convert a character code back to a character?

How to I get the Fixnum returned by the following: "abc"[2] Back into a character? ...

Should there be a difference between an empty BSTR and a NULL BSTR?

When maintaining a COM interface should an empty BSTR be treated the same way as NULL? In other words should these two function calls produce the same result? // Empty BSTR CComBSTR empty(L""); // Or SysAllocString(L"") someObj->Foo(empty); // NULL BSTR someObj->Foo(NULL); ...

Formatting a list of text into columns

I'm trying to output a list of string values into a 2 column format. The standard way of making a list of strings into "normal text" is by using the string.join method. However, it only takes 2 arguments so I can only make a single column using "\n". I thought trying to make a loop that would simply add a tab between columns would do it ...

UTF8 vs. UTF16 vs. char* vs. what? Someone explain this mess to me!

I've managed to mostly ignore all this multi-byte character stuff, but now I need to do some UI work and I know my ignorance in this area is going to catch up with me! Can anyone explain in a few paragraphs or less just what I need to know so that I can localize my applications? What types should I be using (I use both .Net and C/C++, an...

How do I split a mult-line string into multiple lines?

I have a multi-line string literal that I want to do an operation on each line, like so. inputString = """Line 1 Line 2 Line 3""" I want to do something like the following. for line in inputString: doStuff() ...

Custom Date Formating in J2ME

Hi I would like to format a J2ME Date object to only show the date part, not the date and time. What would be the easiest way? Would probably need to include an external library to do this. Any suggestions? Kind regards, IanG ...

Easiest way to get file's contents in C

What is the simplest way (least error-prone, least lines of code, however you want to interpret it) to open a file in C and read its contents into a string (char*, char[], whatever)? ...