string-manipulation

VB date conversion

Is there an easy way to convert a string that contains this: Date: Wed, 5 Nov 2008 13:12:12 -0500 (EST) into a string that contains this: 20081105_131212 UPDATE: I ended up using date.tryparse which is similar to tryParseExact except you don't have to specify the format string. I did have to eliminate the () and the EST for this t...

What is the best way to convert a UTC string to a date in Crystal Reports?

Given a UTC time string like this: 2005-11-01T00:00:00-04:00 What is the best way to convert it to a DateTime using a Crystal Reports formula? My best solution is posted below. I hope someone out there can blow me away with a one-liner... ...

Add spaces before Capital Letters

Given the string "ThisStringHasNoSpacesButItDoesHaveCapitals" what is the best way to add spaces before the capital letters. So the end string would be "This String Has No Spaces But It Does Have Capitals" Here is my attempt with a RegEx System.Text.RegularExpressions.Regex.Replace(value, "[A-Z]", " $0") ...

How do I count the number of occurrences of a char in a String?

I have the string a.b.c.d I want to count the occurrences of '.' in an idiomatic way, preferably a one-liner. (Previously I had expressed this constraint as "without a loop", in case you're wondering why everyone's trying to answer without using a loop). ...

Does the MySQL TRIM function not trim line breaks or carriage returns?

From my experiments, it does not appear to do so. If this is indeed true, what is the best method for removing line breaks? I'm currently experimenting with the parameters that TRIM accepts of the character to remove, starting with trimming \n and \r. ...

How to rewrite this block of code using a StringBuilder in Java?

Given a word, I've to replace some specific alphabets with some specific letters such as 1 for a, 5 for b etc. I'm using regex for this. I understand that StringBuilder is the best way to deal with this problem as I'm doing a lot of string manipulations. Here is what I'm doing: String word = "foobooandfoo"; String converted = ""; conver...

Best way to break long strings in C# source code

I am wondering what is the "best practice" to break long strings in C# source code. Is this string "string1"+ "string2"+ "string3" concatenated during compiling or in run time? ...

JavaScript: Efficiently replace all accented characters in a string?

For a poor man's implementation of near-collation-correct sorting on the client side I need a JavaScript function that does efficient single character replacement in a string. Here is what I mean (note that this applies to German text, other languages sort differently): native sorting gets it wrong: a b c o u z ä ö ü collation-correct...

Using strtok with a string argument (instead of char*)?

I have a string that I would like to tokenize. But the strtok() function requires my string to be a char*. How can I do this quickly? token = strtok(str.c_str(), " "); fails because it turns it into a const char*, not a char* ...

Split a Pascal-case string into logical set of words

I would like to take a pascal-cased string like "CountOfWidgets" and convert it into something more user-friendly like "Count of Widgets" in C#. Multiple adjacent uppercase characters should be left intact. What is the most efficient way to do this? NOTE: Duplicate of http://stackoverflow.com/questions/155303/net-how-can-you-split-a-cap...

How to recognize a path inside a string

Just that... I get a string which contains a path to a file plus some arguments. How can I recognize the path? I thought about the index of the '.' in the file... but I don't like it. What about using regular expressions? Can anyone point me in the right direction? Regards Edit: Theses are valid entries... somefile.msi /a C:\MyFolder\S...

Regular expression to convert substring to link

Hi, i need a Regular Expression to convert a a string to a link.i wrote something but it doesnt work in asp.net.i couldnt solve and i am new in Regular Expression.This function converts (bkz: string) to (bkz: show.aspx?td=string) Dim pattern As String = "<bkz[a-z0-9$-$&-&.-.ö-öı-ış-şç-çğ-ğü-ü\s]+)>" Dim regex As New Regex(pattern...

What is the C# equivalent of Perl's repetition operator?

In Perl print "a" x 3; # aaa In C# Console.WriteLine( ??? ) ...

Format a number with commas, but keep decimals

I'd like to group the digits in a double by thousands, but also output however number of decimals are actually in the number. I cannot figure out the format string. 1000 => 1,000 100000 => 100,000 123.456 => 123.456 100000.21 => 100,000.21 100200.123456 => 100,200.123456 Disclaimers (it's not as straightforward as you think): ...

When is it better to use String.Format vs string concatenation?

I've got a small piece of code that is parsing an index value to determine a cell input into Excel. It's got me thinking... What's the difference between xlsSheet.Write("C" + rowIndex.ToString(), null, title); and xlsSheet.Write(string.Format("C{0}", rowIndex), null, title); Is one "better" than the other? And why? ...

Most efficient way to delimit key.

Say I have a string of 16 numeric characters (i.e. 0123456789012345) what is the most efficient way to delimit it into sets like : 0123-4567-8901-2345, in PHP? Note: I am rewriting an existing system that is painfully slow. ...

How to determine if a string is a number in C#

I am working on a tool where I need to convert string values to their proper object types. E.g. convert a string like 2008-11-20T16:33:21Z to a DateTime value. Numeric values like 42 and 42.42 must be converted to an Int32 value and a Double value respectively. What is the best and most efficient approach to detect if a string is an In...

How do you pull first 100 characters of a string in PHP

I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing. Is there a function that can do this easily? For example: $string1 = "I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing."; $string2 = 100charfunc...

List of strings to one string

Lets say you have a: List<string> los = new List<string>(); In this crazy functional world we live in these days which one of these would be best for creating one string by concatenating these: String.Join(String.Empty, los.ToArray()); StringBuilder builder = new StringBuilder(); los.ForEach(s => builder.Append(s)); string disp = l...

Handling very large strings between SQL Server and .NET code +LINQ

I have an app that needs to handle very large strings between a SQL Server database and .NET code. I have a LINQ query that generates the strings when saving them to the database, but when trying to create the strings from the database, the app crashes with an OutOfMemoryException because of the size of the strings. Do I have to do some...