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.
9
votes
1answer
80 views
Did I implement my string formatting code correctly?
As a small exercise I have written some string formatting and printing functions in C++11. I would like a bit of code review, not so much on the merits of using this over something like ...
8
votes
5answers
720 views
Splitting company name into 3 strings
I wrote an algorithm which should cut a companies name into 3 strings.
Input: 1 String
Output: 3 String.
Conditions:
String 1 2 and 3 shall not be longer then 35 signs. If the Input ...
2
votes
1answer
40 views
Haskell idioms in functions/arguments handling
I came up with this function rangedReplace as an exercice to use recursion and try different ways to make it work (I made at least 3 completely different versions). ...
0
votes
0answers
18 views
String manipulation [on hold]
I wrote the following code for parsing the inputs of type:
./a.out "0.0|10|-0.3|US,JA,PA,CH|0.25,0.25,0.25,0.25|IND,CH,CAN,GER|-1.0" "|" ","
...
2
votes
1answer
51 views
Tough List Comprehension Split Letters and Numbers
So, another challenge from my professor. I've finished it, but wanted to get some feedback, and see how other people might work this problem.
Assume you have a string, such as "Hello 34215 World ...
2
votes
1answer
27 views
Trie SPOJ Problem - PhoneList TLE
In this problem you are given input of phone numbers and you are supposed to determine whether any number is the prefix of another. I have an addchild method that ...
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
0answers
11 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:
...
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).
...
4
votes
0answers
72 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 ...
5
votes
1answer
49 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
53 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
36 views
3
votes
6answers
520 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
36 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
85 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
641 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 ...
2
votes
2answers
78 views
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 ...
4
votes
1answer
20 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"):
...
1
vote
2answers
56 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
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 ...
2
votes
2answers
61 views
4
votes
3answers
65 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
56 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
254 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
149 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
66 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
74 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
128 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
29 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
360 views
3
votes
1answer
83 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
70 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:
...
3
votes
1answer
67 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
125 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
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 ...
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 ...
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 ...
2
votes
1answer
169 views
9
votes
4answers
138 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
432 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
88 views
7
votes
3answers
314 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
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 ...
9
votes
4answers
116 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
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
...
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
...
3
votes
1answer
42 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:
...