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.
6
votes
2answers
577 views
Z-Algorithm for pattern matching in strings
I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings.
...
23
votes
3answers
2k views
5
votes
2answers
569 views
A CSharpish String.Format formatting helper
A while ago I implemented .net's string.Format() method in VB6; it works amazingly well, but I'm sure there has to be a way to make it more efficient.
I'll start ...
7
votes
3answers
918 views
Converting a number to the text representation
Following along with some previous questions:
The @dbasnett original here: Number to Words
@nhgrif's here: Int extension for translating integer to plain English
I wanted to answer the original ...
4
votes
1answer
2k views
Simplifying and optimizing factors and prime factorization generator
My first algorithm for finding the factors of a number was pretty slow and horrible (it started at \$O(n^2)\$, where n was not even the inputted number), but I eventually came up with this new code. ...
21
votes
7answers
3k views
Finding words of different lengths given six letters
I'm trying to find all the 3, 4, 5, and 6 letter words given 6 letters. I am finding them by comparing every combination of the 6 letters to an ArrayList of words ...
14
votes
7answers
7k views
Check for balanced parentheses
Given an expression string exp, write a program to examine whether the
pairs and the orders of
"{","}","(",")","[","]"
are correct in exp.
For ...
15
votes
6answers
2k views
8
votes
4answers
628 views
Align Strings for Output
I wrote a class which can format input so that it is properly aligned.
I'm interested in all suggestions (regarding structure, usability, style, naming, comments, etc).
I'm especially wondering ...
15
votes
4answers
158 views
Int extension for translating integer to plain English
This code was inspired by this question: Number to Words
...
8
votes
3answers
272 views
Printing a week range string in Python
For some reporting, I need to print a human readable date string for the week covered by the report, using just the standard python module library. So the strings should look like:
Dec 29, 2013 - ...
6
votes
1answer
399 views
Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26
I want to implement numbering scheme like Microsoft Word uses for numbering.
first one gets = A,next is B, next is C, .... then AA, then AB,....and so on.
as shown below
...
6
votes
5answers
1k views
String traversal program in C
My task was to write a function in C where a string such as {2210090,34566,87234,564676} would be given as input and the function had to find out the count of ...
5
votes
3answers
95 views
Karp-Rabin String Matching, Part 2
Part 1 is here. I wrote a Java implementation of the Karp-Rabin semi-numerical string matching algorithm. I incorporated the suggestions of @fge and @maaartinus from the other question into my new ...
4
votes
2answers
199 views
Numbers to Text Program - Python Training
I have written a numbers to text challenge for some people in my organisation to practice their Python skills. I am an economist working with pandas, but I am trying to teach them some stuff about ...
3
votes
1answer
173 views
A more readable InStr: StringContains
Consider the following:
If myString = "abc" Or myString = "def" [...] Or myString = "xyz" Then
In C# when myString == "abc" ...
3
votes
3answers
2k views
String in ANSI C?
I'm trying declare a string in ANSI C and am not sure of the best way to do it.
...
2
votes
2answers
204 views
String 'expanding' - reinserting repeating characters
The challenge: Given a String, for each digit in that original string, replace that digit with that many occurrences of the character following it. So a3tx2z yields ...
1
vote
5answers
741 views
Delete each character in one string that matches any character in another
I am trying to solve an exercise in which I am given the following function:
...
73
votes
14answers
11k views
18
votes
9answers
30k views
Converting between std::wstring and std::string
While researching ways to convert back and forth between std::wstring and std::string, I found this conversation on the MSDN ...
12
votes
2answers
607 views
StringBuilder in VBA
In the process of trying to build a serializable data structure, I found myself building large strings, which gets very slow because VBA copies a string every time concatenation is performed.
To ...
15
votes
4answers
286 views
Name Filtering using a Trie
This question suggests a different (improved?) implementation for searching/filtering names based on a search query. This is based on the question here: Name filtering in Java
A Trie allows the ...
6
votes
2answers
4k views
C++ string_cast<> template function
In C++, to simplify string conversion between std::string and std::wstring, I created the following utility template functions:
...
11
votes
3answers
1k views
Customised Java UTF-16
I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters?
...
14
votes
3answers
12k views
12
votes
7answers
3k views
Is this a fast implementation of reversing a string?
I thought of this algorithm today. It seems fast, but how can I know?
...
12
votes
3answers
2k views
Generate all possible combinations of letters in a word
This is a JavaScript function that returns ALL the possible combinations of whatever word the user enters. I am looking to clean this code up a bit...any and all suggestions are welcome!
...
6
votes
6answers
23k views
Reversing words in a string
I have to reverse the string "He is the one" to "one the is He". I have written some programs in Java but am looking for other best solutions. Suggest any possible ways to minimize the current ...
4
votes
1answer
4k views
Faster JavaScript fuzzy string matching function?
I'm using the following function to fuzzy match strings:
...
14
votes
4answers
13k views
Count number of each char in a String
I know there is a simpler way of doing this, but I just really can't think of it right now. Can you please help me out?
...
11
votes
2answers
22k 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:
...
10
votes
4answers
196 views
Bare-bones string library
After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own.
This is a simple dynamic-string library ...
10
votes
2answers
74 views
Poke-a-Dot (Provider)
I need to create variable-length strings of dots/periods/full-stops to add to some text content, in a way that is similar to a formatted table-of-contents:
...
8
votes
1answer
303 views
Very simple PostgreSQL ORM in C++ using libpq
I'm working on a set of helper classes for working with libpq in C++ and I want to be able to pass in objects to the helper classes and have them internally represented as strings when sent to the db, ...
8
votes
2answers
300 views
Given a page of content, determine shortest snippet containing all search phrases (no order required)
A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
6
votes
3answers
2k views
Approximate String Matching Interview Question
I was working on the challenge Save Humanity from Interviewstreet for a while then gave up, solved a few other challenges, and have come back to it again.
The code below generates the correct ...
5
votes
3answers
98 views
Project Euler #8
I was doing Project Euler #8, which asks:
The four adjacent digits in the 1000-digit number that have the
greatest product are 9 × 9 × 8 × 9 = 5832.
...
5
votes
1answer
87 views
Karp-Rabin string matching in Java
I wrote an implementation of the Karp-Rabin string matching algorithm in Java 7, based on the discussion in Section 32.2 of Introduction to Algorithms (CLRS). Clearly, I need more experience with ...
5
votes
4answers
482 views
Decompressing a string
We are given a string which is compressed and we have to decompress it.
(a(bc2)d2)$
"$" indicates end of string.
(abcbcd2)$
abcbcdabcbcd (This is the final uncompressed string.)
My ...
4
votes
1answer
200 views
Simple parsing for string formatting
Recently I submitted some string formatting and printing code (found here) that I wrote as an small exercise. It was implemented naively using string replacement. This time around I wanted to actually ...
3
votes
2answers
119 views
2
votes
2answers
138 views
Determine if a word can be constructed from list of subsets [closed]
The question is explained well by examples in the comments below. Also I request verifying complexity: O( n * n!), where n is the number of words in the subsets. Review my code for optimizations, ...
1
vote
1answer
771 views
Milliseconds to Time string & Time string to Milliseconds
Fast Time conversion
I'm trying to write a very fast time-to-string and string-to-time function.
I noticed that on low CPU mobile devices this function has, even if minimal, impact on the ...
1
vote
3answers
13k views
Calculate all possible combinations of given characters
I was asked in my textbook Lectures on Discrete Mathematics for Computer Science to construct a program that would take an alphabet ({a,b,c} or any combination of ...
0
votes
2answers
841 views
Command line tool for extracting, searching, and converting
I just completed my first real application (command line app). It's simple, but I had no prior knowledge of Python. Everything was hit and miss, with many Python books and help from those in this ...
-2
votes
2answers
415 views
Compressing a string
The task is to compress a string.
eg. "abcbcdabcbcd"
Here as you can see some characters are repeated, so it can be compressed.
"abcbcdabcbcd" -> "(a(bc2)d2)$"
'$' denotes end of string.
My code:
...
12
votes
7answers
2k 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 ...
11
votes
1answer
145 views
Naming numbers in American English
This seems like a popular topic lately, so I took a crack at it.
Related questions are Number to Words and Converting a number to the text representation.
I used this article as a guideline. The ...
10
votes
4answers
245 views
Trimming fgets(): strlen() or strtok()
After a successful fgets(buffer, ...), it is often desirable to trim a potential End-of-Line '\n'.
Of the following 2 methods, ...