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.
3
votes
1answer
25 views
-5
votes
1answer
59 views
Reverse a string [on hold]
I use this for reversing a string, but it has O(n) :
reverse(y.begin(),y.end());
How can I reverse a string in O(n/2) ?
4
votes
1answer
48 views
K&R 1-20 Solution
I'm currently reading the infamous K&R C book and trying to solve Exercise 1-20. My solution looks kind of too simple, but it works. I've searched the web for different solutions, but they all are ...
2
votes
1answer
29 views
Color String Macros and ports of useful PHP string functions
Here is a code file (I use it as a stand alone header file to be included in my projects) that contains macros to generate ANSI encoded strings that when printed are colorized. Also, the module ...
4
votes
3answers
518 views
Eval is evil: Dynamic method calls from named regex groups in Python 3
I'm working on a simple dice roller for a Python IRC bot. The particular game this roller is for uses six different kinds of dice, which I've defined using a simple base class, and created six ...
2
votes
2answers
96 views
Given a string S and Q query strings(q1,q2,…), check for each query string whether or not it is sub-sequence of S
Here is my approach. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
...
-4
votes
0answers
22 views
Using Dictionaries to count first letter in a string [closed]
I've been working on a dictionaries exercise in Python, and I'm fairly new to the language and programming in itself. I've been trying to take a string or list of strings and have my code compare the ...
-1
votes
1answer
29 views
CodeEval “Read More” challenge [closed]
Here is the task, which is basically to truncate lines of input to 55 characters, or to 40 characters (also stripping a space if it happens to end in a space) and appending ...
1
vote
2answers
48 views
Checking whether a string ends with one of a list of suffixes
I want to check if some line ends with any substring defined in some list. Is there a better way than following one?
...
8
votes
2answers
569 views
Comparing two strings to see if string 2 is inside string 1
Here is what I have to do:
Write a function scramble(str1,str2) that returns true if a portion of ...
4
votes
3answers
196 views
Finding the fastest common prefix of 2 strings in Python
I'm comparing my algorithms, slice_prefix and bit_prefix, with existing ones to find the common prefix length of 2 strings as ...
3
votes
2answers
58 views
Comparing a string using a stack
Let L be the language defined as follows:
The words are made up of strings of a’s followed by b’s.
The number of a’s is always equal to the number of b’s.
Examples of words that belong ...
1
vote
0answers
33 views
A bitwise common prefix algorithm in Python
Is my algorithm slow because it has problems? Or, is any bitwise common prefix solution not going to give me the performance I'm looking for?
After profiling my algorithm, I found that over 60% of ...
3
votes
1answer
28 views
Splitting apart a comma separated list
I have a system that outputs a comma separated string into a single column. I need to grab the individual values out of that list. The list could have random spaces and commas that need to be ...
5
votes
1answer
48 views
`read` re-implemented for Int's
I have written a safe read function for haskell (for education!). I think this is fairly idiomatic haskell code, but I'd like to know for sure. If you see anything else that could be improved, please ...
5
votes
4answers
352 views
Rotating strings in Java
I have this Java class for producing rotations of an input string:
StringRotator.java
...
3
votes
1answer
40 views
Reading arbitrarily long lines from a file that is redirected as input
So I have a file with a list of dates that are to be redirected as input to stdin and what the program does is it searches for valid dates, appends them to the output file and then appends all the ...
5
votes
1answer
54 views
Comparing two approximate string matching algorithms in Java
Problem description
Given a text \$T[0..n)\$, a pattern \$P[0..m)\$, and a nonnegative
integer \$k\$, report all positions \$j \in [0..n)\$ such that \$ed(P,
T(j - l..j]) \leq k\$ for some \$l \geq ...
3
votes
3answers
490 views
Reverse words in Java
Short and Spicy question is that If input is how are you and output should beyou are how.
...
1
vote
1answer
27 views
Remove non-printable characters from string in Python 3
My aim is to print bytes string lines in Python 3, but truncate each line to a maximum width so that it fits the current terminal window.
My first attempt was only ...
5
votes
1answer
341 views
Anagram finder in F#
I've been learning F# for a month or so and I'm wondering how good my "functional" aspect of coding is. When I first started, I did this using an iterative approach with a lot of <- and mutables ...
3
votes
1answer
49 views
Clojure reverse multiple times
I have a piece of Clojure code that reverses a string recursively.
It is working but too slow (because I got the problem from Codewars and I cannot validate it ...
3
votes
1answer
48 views
Comparing a string that can hold a numeric value
I am refactoring a part of big old system developed in Java. I came across a situation where we are migrating some data types, and there will be use of both types. For compatibility, as all the old ...
2
votes
0answers
91 views
Number-to-words translator
I've created a class that translates an integer into words in an English (not British) format. My first human language is not English, and I don't have a good idea of a truly right way to read ...
3
votes
2answers
71 views
Parse Numerals from a String in Golang
I recently tried my hand at writing Go code for a project I'm working on. In order to help myself get a better grasp I decided to write a simple yet somewhat practical program for parsing numeral ...
-2
votes
2answers
94 views
Checking for matching delimiters using multiple stacks or counters
I know my algorithm is very naive and slow for this problem. I would like to learn how to improve upon it?
...
3
votes
1answer
58 views
Trimming whitespace in Excel cells
I often receive large Excel-sheets in which data has been inserted via copy and paste. Usually a lot of the cells contain whitespaces at the beginning and the end before / after the actual value.
I ...
1
vote
1answer
43 views
INSERTing a student info record based on form inputs
I want to improve my coding skills. How do I write this code with concatenation
...
0
votes
0answers
35 views
Permuted index generator (second version)
I have implemented a second program that produces a permuted index; here is my first solution.
As advised in one of the answers, I split my program into two classes.
Could anyone tell me if I did ...
0
votes
2answers
50 views
Implementing permuted index in C++
I have implemented a program that produces a permuted index.
Actually it is this exercise:
http://stackoverflow.com/questions/4015016/what-is-a-permuted-index
Could anyone tell me if I did something ...
5
votes
2answers
89 views
Counting occurrences of a word in a file
This gives me the output of how many times the word is in the file. (I will eventually want to enhance the program to output on what line of the file the word is.)
...
1
vote
0answers
39 views
Progressively split and map a large, line-based string
Goal
I have a large string (~10MB in ~400k lines). I want to "efficiently" split it on a delimiter and map the resulting sets of lines. Efficiently is defined as something that is fast (wall time), ...
3
votes
3answers
58 views
generate word list based on Spanish text file
I'm a beginner and wrote a program takes a text file and writes a downcased vocabulary list to another text file. I intend to use it mainly to work with text in Spanish, so I added a line to downcase ...
2
votes
2answers
37 views
Computing the largest substring starting with a substring
Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length.
...
3
votes
1answer
188 views
Method to replace all spaces in a String with '%20'
Problem statement (extracted from cracking the coding interview):
Write a method to replace all spaces in a string with'%20'. You may assume that
the string has sufficient space at the end of the ...
4
votes
4answers
194 views
Validating a tab-delimited string
This code checks if string has correct format for passing to struct. Correct format needs to be [123456789'\t'First Name'\t'Last Name'\t'City]. I didn't know how to ...
2
votes
2answers
96 views
9
votes
4answers
2k views
Randomly generate spelling mistake in string
My code will generate a spelling mistake inside of a string 50% of the time.
It will retrieve a letter from a random index in the string like, "t" and then duplicate that letter like, "tt" and store ...
1
vote
1answer
42 views
Finding a substring within a string using regular expressions
I'm new to Java and is trying to find a substring within a string using regular Expressions. I was just wondering if there are any alternative ways to achieve the same goal, or in a more elegant or ...
3
votes
2answers
88 views
Simple function to generate a list of letters
I would like get some suggestions for improvement of this function, and alert me about any dodgy practices that you find.
I have been trying to learn python for a short time now and I would like to ...
3
votes
1answer
31 views
1
vote
1answer
46 views
Creating a RegExp in JavaScript from user input
My goal is to accept user input regex in the following forms
/regex|here/i
/regex|here/
...
1
vote
2answers
52 views
Regex to match strings safely
The following regex is meant to improve stringmatching by sanitizing the user -defined commandPrefix and checking for whitespace and line-endings after the ...
2
votes
2answers
201 views
Parsing JSON in one go
I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
1
vote
1answer
49 views
-1
votes
2answers
82 views
JSON string parsing
I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
3
votes
3answers
55 views
2
votes
2answers
46 views
splitting multiple joined words, port from perl to PHP
Though i have never worked on perl, not even once.
I have ported the perl code into PHP and it seems like giving a correct result. But as I am going to use it on production server.
I want this code ...
1
vote
3answers
77 views
Duplicate Line Finder
I recently wrote a program that reads a plain text file, and compares every line and alerts you if any are similar, based on a float value that you pass in to a function.
...
2
votes
2answers
40 views
Text 'guesser' / tumbler like animation
I made a tumbler thingy...
Do you see possible bugs in the code or any improvements I could do?
...