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.
4
votes
3answers
245 views
Rotating strings in Java
I have this Java class for producing rotations of an input string:
StringRotator.java
...
3
votes
0answers
15 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
46 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
480 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
17 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
318 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
41 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
78 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
61 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 ...
3
votes
1answer
49 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
41 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
33 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
48 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
81 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
37 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
55 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 ...
1
vote
0answers
17 views
Python: Recursion Practice
Problem:
Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length.
sub_sandwich("catcowcat", "cat") → 9
...
3
votes
1answer
183 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
190 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
84 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
38 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
86 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
30 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
198 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
77 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
54 views
2
votes
2answers
44 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
75 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?
...
3
votes
3answers
769 views
StringBuilder vs string.concat
I was reading this article about StringBuilder vs string.concat and couldn't figure out which one would be better in the ...
6
votes
4answers
239 views
Numeric integrity check
I'm a beginning C programmer. I need a function that will take a string and determine if it's a number. The data is coming from files created by different people and the number formats WILL vary. So ...
10
votes
1answer
438 views
Implementing a String class using reference count
Design a STRING class. Provide support for:
Assigning one object for another
Two string can be concatenated using + operator
Two strings can be compared using the relational operators
...
1
vote
2answers
40 views
Anchor Text String Transformation in Swift
I need to convert a string using these rules:
Downcase the string
Replace spaces, a blacklist of "invalid" chars, and non-ascii letters (like é) with -
Replace ...
0
votes
1answer
41 views
Parse a string to get a SectorId
In mobile phones technologies, a SectorId is a 128-bit value broadcast by a 1xEV-DO BTS system.
That is a 16 bytes data.
I made a structure to store them:
...
4
votes
4answers
200 views
Changing a character in a string at a specified index position
Could you please tell me what you liked or may have disliked about this code? What can be made better?
...
7
votes
3answers
3k views
Replace space with %20
This is not very memory-efficient. Can you please suggest a better way or improvement?
...
9
votes
5answers
2k views
Check if a string has 20 numbers in a row in it
My code will check if the variable myString has 20 running numbers. I'm new to JavaScript and I'm wondering if there is a simpler way to do this. How can I shorten ...
1
vote
1answer
57 views
Converting bytes to an escaped hexadecimal string
I wrote this function to convert an array of bytes to a C/C++ string representation using hexadecimal escape codes (\xhh). Any suggestions are welcome:
...
2
votes
1answer
60 views
String similarity calculation
For string similarity, it is defined as longest common prefix length. For example, "abc" and "abd" is 2, and "aaa" and "aaab" is 3.
The problem is calculate the similarity of string S and all its ...
4
votes
1answer
47 views
3
votes
1answer
58 views
Check string having unique character or not without additional data structure
Here is my code without using additional data structures. Assuming all the characters are alphabetical and character checks are case-insensitive.
...
2
votes
0answers
48 views
Converting Chess FEN Notation to a Tuple and Back
This module is going to be part of a larger ElixirChess library for validating chess positions and moves, but I started with the core of it which is parsing a ...
1
vote
1answer
128 views
Converting from strings to byte arrays with LINQ in C#
I'm taking in a string of input from the command line, and when prefixed by 0o or 8# interpreting it as an octal string. I'd ...
4
votes
3answers
92 views
Java 8 String Unique Permutations in Parallel
Is there a better way to do this Java 8 String Unique Permutations in Parallel
...
5
votes
1answer
280 views
Longest Substring in Java
This is my function for determining the Longest Substring between two strings in Java.
...