Tagged Questions
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.
5
votes
2answers
97 views
Output int from string input
This takes a string input like 1,2,3,4,5, splits it using , delimiter, converts each char to int and output it in a single line ...
2
votes
0answers
38 views
JavaScript function that returns 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!
...
4
votes
1answer
65 views
Converting string array to string (and vice-versa) for storing via XML
I'm using XML to store data and I need to store a string array in it. The best way (that I can think of) to store a string array is by converting it to a single string. In order to do that, I'm using ...
1
vote
0answers
17 views
Identifying “Matching Bigrams” in Large Text Collection
I have a large number of plain text files (north of 20 GB), and I wish to find all "matching" "bigrams" between any two texts in this collection. More specifically, my workflow looks like this: for ...
6
votes
1answer
91 views
Finding common strings among 2 arrays of strings of length 1, sorted alphabetically in O(n) time complexity
The problem:
Start with two arrays of strings, a and b, each in alphabetical order,
possibly with duplicates. Return the count of the number of strings
which appear in both arrays.
...
3
votes
2answers
65 views
Capitalize all words in sentence string in Ruby
I have created the following code:
def LetterCapitalize(str)
str = str.split(" ").each {|word| word.capitalize!}
str = str.join(" ")
return str
end
This ...
4
votes
1answer
77 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 ...
0
votes
0answers
19 views
Segfault when trying to sort a linked list of names using a bubble sort [closed]
I am trying to sort a linked list in alphabetical order using bubble sort, but I am getting a segfault when I run the program. I can print off the names before sorting, but when I sort them and try to ...
9
votes
2answers
252 views
+100
Memory-efficient string collection
My goal is to create a memory-efficient (immutable) collection of strings. The imagined use-case is checking for valid words in a Scrabble-like game.
Wikimedia Commons has a pretty good summary of ...
5
votes
1answer
120 views
Replacing occurrences in NSString and NSMutableString
I ran it and it's working, but I just want someone to double check that I followed the directions. Any suggestions or corrections will be appreciated.
Assume you have a ...
9
votes
1answer
143 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
743 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 ...
3
votes
1answer
50 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). ...
2
votes
1answer
68 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
112 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
13 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
72 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
0answers
85 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
52 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
56 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
38 views
3
votes
6answers
527 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
37 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
104 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
651 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
83 views
5
votes
2answers
66 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
60 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
161 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
66 views
4
votes
3answers
69 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
57 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
260 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
158 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
68 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 ...
3
votes
2answers
77 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
32 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
362 views
3
votes
1answer
90 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
73 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
69 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 ...
6
votes
2answers
135 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
84 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
170 views
9
votes
4answers
145 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 ...