string

using the literal '@' with a string variable

I have a helper class pulling a string from an XML file, that string is a file path (so it has backslashes in it). I need to use that string as it is... how can I use it like I would with the literal command? instead of this: string filePath = @"C:\somepath\file.txt"; I want to do this: string filePath = @helper.getFilePath(); //ge...

Painless way to trim leading/trailing whitespace in C?

Is there a clean, preferably standard method of trimming leading and trailing whitespace from a string in C? I'd roll my own, but I would think this is a common problem with an equally common solution. ...

php String Concatenation, Performance

In languages like Java and C#, strings are immutable and it can be computationally expensive to build a string one character at a time. In said languages, there are library classes to reduce this cost such as C# System.Text.StringBuilder and Java java.lang.StringBuilder. Does php (4 or 5; I'm interested in both) share this limitation? ...

Sorting strings is much harder than you thought!

Sorting a list of strings in a way that makes sense to a human is a very complex task. It's not just about comparing ASCII values. Usually, the case doesn't matter. You probably want "File 2" to be sorted before "File 11". In German, 'Ä' often comes at the beginning of the alphabet, whereas in Swedish it's towards the end. And what about...

String Format Date - C# or VB.NET

Date coming out of a database, need to format as "mm/dd/yy" For Each dr as DataRow in ds.Tables(0).Rows Response.Write(dr("CreateDate")) Next ...

Ruby - Convert File to String

I need an easy way to take a tar file and convert it into a string (and vice versa). Is there a way to do this in Ruby? My best attempt was this: file = File.open("path-to-file.tar.gz") contents = "" file.each {|line| contents << line } I thought that would be enough to convert it to a string, but then when I try to write it back ou...

Restrict a string to whitelisted characters using XSLT 1.0

Question Using XSLT 1.0, given a string with arbitrary characters how can I get back a string that meets the following rules. First character must be one of these: a-z, A-Z, colon, or underscore All other characters must be any of those above or 0-9, period, or hyphen If any character does not meet the above rules, replace it with an ...

How do you handle strings in C++?

Which is your favorite way to go with strings in C++? A C-style array of chars? Or wchar_t? CString, std::basic_string, std::string, BSTR or CComBSTR? Certainly each of these has its own area of application, but anyway, which is your favorite and why? ...

Better Way of Manipulating RichText in C#?

I need to create and copy to the clipboard some RichText with standard "formatting" like bold/italics, indents and the like. The way I'm doing it now seems kind of inelegant... I'm creating a RichTextBox item and applying my formatting through that like so: RichTextBox rtb = new RichTextBox(); Font boldfont = new Font("Times New Roman"...

How can I capture the result of var_dump to a string?

I'd like to capture the output of var_dump to a string. The PHP docs say As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example). Can someone give me an example of how that might work? print_r() isn't a...

Is there a buffered version of CComBSTR that makes string concatenation more efficient?

I have several projects where I need to append strings to a BSTR/CComBSTR/_bstr_t object (e.g. building a dynamic SQL statement). Is there an out-of-the-box type in the WinAPI to buffer the concatenation (like StringBuilder in .NET), or do I have to write my own? From what I know about the append methods, they perform re-allocation. ...

What is the maximum possible length of a .NET string?

What is the longest string that can be created in .NET? The docs for the String class are silent on this question as far as I can see, so an authoritative answer might require some knowledge of internals. Would the maximum change on a 64-bit system? [This is asked more for curiosity than for practical use - I don't intend to create any ...

How do I replace the *first instance* of a string in .NET?

I want to replace the first occurrence in a given string. How can I accomplish this in .NET? ...

What's the best way to count keywords in JavaScript?

What's the best and most efficient way to count keywords in JavaScript? Basically, I'd like to take a string and get the top N words or phrases that occur in the string, mainly for the use of suggesting tags. I'm looking more for conceptual hints or links to real-life examples than actual code, but I certainly wouldn't mind if you'd like...

How do I wrap a string in a file in Python?

How do I create a file-like object (same duck time as File) with the contents of a string? ...

Is there any difference between "string" and 'string' in Python?

In PHP, a string enclosed in "double quotes" will be parsed for variables to replace whereas a string enclosed in 'single quotes' will not. In Python, does this also apply? ...

Fastest way to convert a possibly-null-terminated ascii byte[] to a string?

I need to convert a (possibly) null terminated array of ascii bytes to a string in C# and the fastest way I've found to do it is by using my UnsafeAsciiBytesToString method shown below. This method uses the String.String(sbyte*) constructor which contains a warning in it's remarks: "The value parameter is assumed to point to an array re...

Simplest way to use "BeanUtils alike" replace

Is there any libraries that would allow me to use the same known notation as we use in BeanUtils for extracting POJO parameters, but for easily replacing placeholders in a string? I know it would be possible to roll my own, using BeanUtils itself or other libraries with similar features, but I didn't want to reinvent the wheel. I would...

How do I parse a number from a String that may have a leading zero?

In ruby I am parsing a date in the following format: 24092008. I want to convert each section (year, month, date) into a number. I have split them up using a regex which produces three Strings which I am passing into the Integer constructor. date =~ /^([\d]{2})([\d]{2})([\d]{4})/ year = Integer($3) month = Integer($2) day = Int...

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: id string 1 A 1 B 2 C to this: id string 1 A B 2 C ...