A string is a sequence of zero or more characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.
2
votes
0answers
9 views
Parsing time ranges with PyParsing
The following code is intended to parse a string of the following format and return whether the current time falls in that window:
...
3
votes
1answer
55 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).
...
3
votes
0answers
62 views
String matching algorithm
I have been going through algorithms and data structures and recently came across string matching algorithms. I have not yet wrapped my head around the significance KMP algorithm so I came up with ...
3
votes
1answer
43 views
Bi-directional atoi()
I am implementing atoi() by traversing a string from the beginning as well as from the end. Is there anything I can improve?
...
4
votes
1answer
49 views
Permutations program in Python
This code asks for letters and a number of letters per word and generates all possible permutations. Then compares those permutations with an English dictionary and creates a list with all the words ...
0
votes
2answers
32 views
3
votes
6answers
502 views
Code Hunter 2.06: Count occurrences of 'a' in a string
I'm playing Code Hunt on level 2.06 (loops). This level is about counting the number of "a" in a String.
...
2
votes
1answer
33 views
More Pythonic version of finding substring with one glob-like expression
Giving the following example list the task is: find out whether the
second expression is in the first one. * shall be considered as a
wildcard for any ...
10
votes
1answer
62 views
Swift string multiplication
I like Ruby's string multiplication so I thought I'd see if I could do it in Swift. I came up with these implementations:
...
9
votes
4answers
630 views
Determine if one string occurs at the end of another
Exercise 5-4
Write the function strend(s,t), which returns one if the string t occurs at the end of the string ...
5
votes
2answers
56 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 ...
4
votes
1answer
17 views
Converting the integers to their equivalent string representations
I have the following function which converts an integer (such as 103 to its string representation "one hundred three"):
...
2
votes
1answer
38 views
Given suffix array and a pattern, search if given pattern exists
Given a suffix array for a word, check if a pattern (consecutive chars) exists.
Example:
A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false ...
5
votes
4answers
153 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 ...
2
votes
2answers
57 views
4
votes
3answers
64 views
String self-similarity
It's a string problem I have been making on Hackerrank. It is executing fine on all test cases except the last two. These last two test case are declaring it "Terminated due to time out".
C programs ...
2
votes
2answers
55 views
String sanitisation function
I have a search function on my website. In addition, elsewhere I have a place where users can submit categories for their posts. I want the categories to have an uppercase first letter and the rest ...
4
votes
2answers
244 views
Manipulating filenames using Python
I was tasked with creating a script to be able to rename some files and then move them into different folders based on a code in the filename.
...
6
votes
1answer
140 views
Converting any PHP function toString() like in JS
In JavaScript, any function is basically an object on which you can call (function(){}).toString() to get it's underlying code as a string.
I'm working on a ...
6
votes
1answer
64 views
Text Analysis web page
For a homework assignment, I made a web page that has a text area. The user inputs some text, hits the analyse button, and the output is supposed to be a list of the frequency of words of a given ...
2
votes
2answers
72 views
Word counter script
I made a word counter. It works as long as there aren't any lone punctuation marks. How could it be improved? (Could it be made simpler? Are the comments detailed/clear enough? etc.) I know it's ...
2
votes
2answers
122 views
Check Abecedarian word
An 'abecedarian' is a word whose letters appear in alphabetical order.
Write a program which will determine whether the given word is
abecedarian or not and print ...
2
votes
1answer
28 views
Optimizing string replacement program that uses recursion
I have the following string replacement program for a string of size 256:
I am replacing the string
"\'"
with the string
'
Please suggest any modifications if needed or any ...
7
votes
2answers
358 views
3
votes
1answer
77 views
Converting from std::wstring to std::string in Linux
I was bothered by inability of C++ to mix cout and wcout in the same program - so I've found this question:
Converting between ...
2
votes
1answer
67 views
Easiest way to remove extra spaces from user input?
What I want to do:
Take user input strings and add them together with proper spacing.
HTML:
...
4
votes
1answer
65 views
Breaking after one of several string replaces occur
I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid ...
5
votes
2answers
121 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.
...
4
votes
1answer
59 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 ...
3
votes
1answer
58 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 ...
5
votes
3answers
283 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 ...
2
votes
1answer
168 views
9
votes
4answers
134 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
3answers
423 views
Searching for pseudo-palindromes (“semordnilaps”)
I was interested to know which words of the English language, when spelled backwards, are still valid words (e.g. "drawer", which when spelled backwards is "reward"), so I wrote a small program to go ...
0
votes
1answer
85 views
7
votes
3answers
311 views
Operations on strings in Java
I have a program that makes operations on strings and this is the principal function of one of those operations. This works perfectly, but it is not efficient:
...
3
votes
3answers
421 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 ...
8
votes
4answers
108 views
Mimic sprintf with std::string output
I know that stringstreams are the C++ recommended way to create formatted text. However, they can often become quite verbose, especially when compared to the succinct format strings of ...
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
228 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
...
4
votes
1answer
71 views
Wordgenerator algorithm using Java collection
Problem Statement
Prompt the user for the order
statistic n: 1, 2, 3, etc.
Read a file of tokens, building a map
...
0
votes
0answers
7 views
Multiple choice quiz that repeats answers that you have gotten incorrect, then starts again when you have answered them all correctly [migrated]
I'm pretty new to programming (been learning for about 2 weeks) and my goal is to eventually design a revision style multiple choice quiz that randomly generates questions and repeats the questions ...
3
votes
1answer
41 views
Stripping out all /* */ comments from a paragraph
I've written this code keeping the following cases in mind and I think I've covered them all. I'd really appreciate if someone could help me determine if I've covered all of them.
Cases I considered:
...
3
votes
2answers
101 views
Calculate all possible combinations of an array of arrays or strings
I'm using code adapted from this Stack Overflow question to calculate all possible combinations from an array, which may contains strings.
For example:
...
1
vote
1answer
40 views
Trimming exactly two white spaces from string at O(N) [closed]
This is the optimized code I have written for removing/trimming one white space from a given string. I'm required to remove exactly two spaces from the string at the same cost of \$O(N)\$ by ...
2
votes
1answer
29 views
Multiplying a numeric string with the “vedic method”
This is vedic method multiplication. This code takes time on a very long numeric string, and I want to optimize it. I also apply recursion on multIndices (this ...
4
votes
3answers
151 views
Penney Game - mapping macros to strings
The SPOJ problem:
Given a 40 character string representing outcomes of 40 coin tosses,
find the frequency destribution of all the possible outcome triplets.
So, for string like : HHHH....40 Hs ...
4
votes
3answers
90 views
4
votes
2answers
49 views
Efficient use of regular expression and string manipulation
The following is my solution to Java vs C++. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle.
...
5
votes
4answers
235 views
Replacing strings to have a single blank
In Kernighan and Ritchie (the C programming language):
Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.
I wrote the following code. ...