Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 39186

A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.

4 votes

Processing a list to build an ip in a string format

For those who have to use an old .NET Framework (prior to 4.0). To eliminate removing of the last character, you could use the String.Join method: return String.Join(".", ipList.ConvertAll(x => x.ToS …
Dmitry's user avatar
  • 4,589
5 votes

Split a string into chunks of the same length

There are only two things I can suggest: You don't need to create a List<string> first and then copy it to an array via ToArray() extension method. You know an exact number of elements in the output …
Dmitry's user avatar
  • 4,589
5 votes

Replace fifth space with new line

You could use the StringBuilder class and the String.IndexOf method as follows: Option 1 private static string ReplaceNthOccurrence(string input, int n, char find, char replaceWith) { int inde …
Dmitry's user avatar
  • 4,589
7 votes

Reverse a sentence quickly without pointers

The shortest code I can produce is: private static string Reverse(string input) { return String.Join(" ", input.Split(' ').Reverse()); } But the following alternative should be much faster: pr …
Dmitry's user avatar
  • 4,589
2 votes
Accepted

Delimited File Reader

I'd prefer to rely on the builtin functionality as much as possible. I want to believe that use of the builtin stuff makes my code more readable and probably faster. So my proposal is: public class …
Dmitry's user avatar
  • 4,589
2 votes

Determine if two strings with no repeating characters are permutations of each other

= second.Length) { return false; } return SetEqual(first, second); } If you are sure that strings contain only unique chars, there is a more efficient approach using the HashSet …
Dmitry's user avatar
  • 4,589
2 votes

Is there a way to simplify getting the character that appears the most in a collection with ...

The following code part could be inefficient for large sets: .OrderByDescending(x => x.count) .First(); We don't need sorting at all, we need just to find an item with the maximum value. Let's create …
Dmitry's user avatar
  • 4,589
11 votes
Accepted

Parse a specified arithmetic type from string

I'd prefer to use a dictionary for this. private delegate bool TryParseDelegate<T>(string text, out T value); private static readonly Dictionary<Type, object> TryParsers = new Dictionary<Type, obj …
Dmitry's user avatar
  • 4,589
2 votes

Finding longest phrase algorithm

The only approach I can suggest is to use an LCP array. Since my first implementation has extremely slow sorting of suffic array, I decided to base my new solution on the Sais implementation of the …
Dmitry's user avatar
  • 4,589
6 votes

Check for balanced parentheses

The easiest way I can see is to create 2 arrays of parentheses: 1 for the open ones and 1 for the close ones. We will use these arrays to check whether current char is a parenthesis and obtain its ind …
Dmitry's user avatar
  • 4,589