Tagged Questions
7
votes
6answers
425 views
7
votes
3answers
107 views
Compare string with wildcard string
I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it.
...
2
votes
2answers
3k views
Formatting a datetime string in the YYYYMMDD format
I'm working with some strange APIs that requires the dates to be sent in the YYYYMMDD format.
I was thinking of doing something like this:
...
4
votes
1answer
68 views
Method to return a string of max length (in bytes vs. characters)
In my (c#) code, I need to generate a string (from a longer string) which when UTF-8 encoded, is no longer than a given max length (in bytes).
...
5
votes
2answers
60 views
Convert string to multiline text
I made this method that takes any string and transforms it into a multiline text l; each line having the max (character) length specified by the rowLength ...
5
votes
4answers
158 views
Faster method to find data using search word?
I need to search through a string array to find every occurrence of "Parameters Table", and between each "Parameters Table" and the next, get another string from a specified index (that remains ...
3
votes
1answer
61 views
Displaying TimeSpan as largest interval (with units) - Part II
[This is a follow-up question to: Displaying TimeSpan as largest interval (with units). The code listed here has been refactored since the original question was posed. Please note that the scope of ...
3
votes
3answers
425 views
Beautifying Dates
There has got to be a better way to do this. I have a method which returns either your standard "01/01/2014" Date or "January 1st, 2014" Date of the assembly file write time. Any suggestions on ...
4
votes
1answer
67 views
Convert hex string to byte array
The goal is to convert a hex string to a byte array with the following requirements:
\$O(1)\$ additional space apart from input and output.
\$O(n)\$ runtime
This mostly just prohibits creating a ...
5
votes
3answers
288 views
Displaying TimeSpan as largest interval (with units)
The following method is used in a call center application to display an approximation of remaining time. The call center telephone operator would inform the caller that they could perform their ...
5
votes
3answers
1k views
Converting a range of integers from a string to an IEnumerable
Goal
Convert the following into an IEnumerable of integers accounting for the x-y ranges:
...
2
votes
2answers
50 views
Return custom assembly attribute variables
I have a custom attribute in my assembly called SemverAttribute, and I have a helper class called AppInfo that has a function to return a number called the Semver number. It accepts an id of null-6. ...
5
votes
3answers
231 views
Shorten code to perform search based on four slash-delimited parameters
How can I make this code more compact?
It is a ASP.net WebForms project
It is a SinglePageApplication for searching in list mode and map mode.
I have many paths for a page.
/Denmark
...
6
votes
2answers
120 views
Tight loop, string manipulation and calculations
I'm working on some precompilation operations for a world compiler. Currently to identify flags placed by the level designer I need recognize when a specific entity exists at specific coordinates from ...
6
votes
2answers
67 views
A method which, given a string, returns a string in which each character is separated by an asterisk
Use recursion in the solution.
I would really appreciate if you can help me to find a better way to do it.
...
4
votes
2answers
73 views
Given a string, return a string where every character in the original is doubled
For example, given the string "xyz", return the string "xxyyzz".
I was given this as a part of a test. I would really appreciate if you can help me to find a better way of doing it.
I came up with ...
5
votes
5answers
396 views
Determining whether a string ends with one of a few given options
I wrote the following function to determine whether a string ends with one of a few given options.
I'm sure it can be written more elegantly, probably avoiding the loop.
...
5
votes
2answers
1k views
Reversing each word of a string while keeping the case index
I was given a simple requirement for reversing a string. The requirement is as follows:
In any programming language, create an input that accepts "My name is Albert McDonald." and outputs the ...
3
votes
2answers
384 views
Encryption/decryption of data
I'm trying to work with some encryption/decryption of data. It was some hard work for me to get it working with some buffers and what not.
This is the code I came up with:
...
2
votes
1answer
96 views
5
votes
1answer
119 views
String modification application
Below is working code of a semi complete program. Its purpose is to take an input string of any type and modify it based on rules defined for each type. So in this example I pass it a string in CSV ...
2
votes
2answers
76 views
Increase performance of string matching function
I've benchmarked my program, and have discovered that the single function taking the most time is the one that does the following.
Takes string that is a delimited list, and splits it into ...
11
votes
7answers
530 views
Class for handling unit conversions
I am creating a class to be the end all defacto class for handling unit conversions. This is particularly difficult in my company's industry where imperial architectural strings are used as units. I ...
5
votes
1answer
156 views
Simplify C# Helper Class to change property of string when serializing for Json.Net
Is there any way to simplify the following C# helper class to numerate a string for Json.Net?
...
3
votes
1answer
212 views
Searching text files for string patterns that are each defined in their own classes
I'm trying to implement interfaces in my design but not sure if this is correct or if there is a better way to do it.
What I need to do is
open a text file
keep searching blocks of text until I ...
3
votes
1answer
54 views
Preprocessing Markdown Documents for Keywords
I recently added a feature to my application to serve arbitrary markdown documents from a directory. This is designed to allow authors to populate a folder full of help documents, and be able to view ...
5
votes
2answers
121 views
3
votes
1answer
93 views
Which approach is preferable string parsing?
I want to find total word count in string. I have two methods as mentioned below.
...
11
votes
2answers
9k views
Integer to Alphabet string (“A”, “B”, …“Z”, “AA”, “AB”…)
So this question is prompted by two things.
I found some code in our source control doing this sort of things.
These SO questions:
...
3
votes
2answers
154 views
How to get the Split value from collection?
I have the following key value pair in an array, and am trying to extract and load them into a collection.
The below code is working but it can be optimized using Linq:
...
7
votes
6answers
352 views
Cleanest way to place values into strings
I am trying to standardize the way I write code. Which is the best way to place the values into a string, method 1 or 2?
...
1
vote
2answers
2k views
13
votes
7answers
8k views
Random string generation
I'm using this C# function to generate random coupons for a system. How can I improve it?
...
4
votes
1answer
788 views
Parsing XML to create IList
Here's a class I created to parse XML to create an IList.
It seems to me that this is something that will be done a lot in general by a lot of different programs. Is there a more standard way of doing ...
4
votes
2answers
569 views
Splitting a string of random length
I am currently using this code, but I am pretty sure there is a better way of doing it:
...
2
votes
2answers
170 views
Should I create an empty string and append through a foreach loop or should I use StringBuilder? [closed]
Here's the current code:
...
10
votes
8answers
1k views
Replace strings in a file
I had to create an executable to search and replace strings in a file. This is to be used in my installer for text file manipulation. I have various placeholders in configuration files that I need to ...
3
votes
3answers
140 views
String Extension improvement
I am creating a string extension to validate some input.
My scenario is when we have a string it will format it according to following guideline.
If the sample string is “One Two Three Four Five” and ...
8
votes
1answer
790 views
Adding N characters to a string
I need to preprend N spaces to a string to make it 10 characters in length. I came up with the following method, but since it is going to be called often, I want to ensure it is optimized. Could this ...
5
votes
1answer
207 views
First attempt at dealing with command-line args
A little while ago I was fiddling with dependency-injection and came up with this small WPF application that I can launch with command-line arguments.
Not only this was my first experiment with DI, ...
0
votes
1answer
190 views
Random string generator [closed]
I have made a simple number generator, and I have a question: is it possible for the generator to eject "red", "blue", "green", " yellow" and "white" instead of the numbers 1-5?
...
2
votes
3answers
107 views
Function for encoding strings in-place
I recently wrote a function that replaces every white space with '%20', just for fun (and sharping my coding skills). The input string is terminated with extra white spaces, with the length that the ...
3
votes
1answer
287 views
String Interpolation / Word Matching with XML in C#
I'm working on a project where I need to map XML values to field names. Classic CS problem, I think I've got a pretty good approach but would like feedback.
For example: ...
6
votes
3answers
335 views
2
votes
1answer
128 views
3
votes
1answer
191 views
A reliable way to remove consecutive appearances of a substring
I'm attempting to write a piece of code that is supposed to remove consecutive appearances of a string (not a single character) in a ...
4
votes
3answers
2k views
Longest common substring
I wrote a program to find the longest common subsequence among several strings. I used a naive algorithm and implementation.
The motivation was solving the Rosalind problem at ...
3
votes
1answer
218 views
Inefficient usage of string.format?
I have some sample code where I used string.Format but after reading about benchmark performances by other people I believe that it may be better to do multiple ...
8
votes
2answers
942 views
String join of distinct string
I have a class like this one:
class EmailClass
{
public string MailAdresse { get; set; }
public string MailAdresseCC { get; set; }
}
Through a JSON ...
7
votes
1answer
284 views
Can I use string.Format to represent these formatted numbers more succinctly?
string taskNumber = order.ID.ToString("D6") + "-" + task.ID.ToString("D4");
I'm writing out two numbers separated with a dash. The first number is padded with ...