Questions tagged [strings]
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.
97
questions with no upvoted or accepted answers
6
votes
0answers
132 views
Generate unique random strings considering collisions
I'm coding a random strings generator. It's working, but I'm not sure if this is efficient.
...
6
votes
0answers
2k views
Finding the length of arbitrary ASCII character strings
I have implemented this MIPS code to determine the length of given ASCII character strings.
Is there a simpler way to implement this code? Is there is a built-in function in MIPS?
Given String:
...
6
votes
0answers
757 views
Parsing Lua 5.2 strings with patterns
I wrote some code to parse Lua 5.2 strings in Lua 5.1, using patterns. It works perfectly as far as I tested.
...
5
votes
0answers
42 views
calculating upper bound on normalized weighted levenshtein distance
Current implementation
I am using a normalized weighted Levenshtein distance for two utf32 strings with the following costs (insertion: 1, deletion: 1, replacement: 2). The normalization is performed ...
5
votes
0answers
241 views
Palindrome insertion challenge
Here is my solution to the following Daily Coding Problem challenge
Given a string, find the palindrome that can be made by inserting the
fewest number of characters as possible anywhere in the ...
5
votes
0answers
212 views
Rabin-Karp algorithm implementation
This code uses the Rabin-Karp algorithm to compare two text files. It takes a few minutes when both files contain around 1000 words. How can it be improved?
...
5
votes
0answers
115 views
Tokenizing and sorting the strings of a text file with the results of a public competition
I made this script to carry out a specific real-life task, which was to sort a list of candidates in a public competition by grade. The file with the informations consists of a text file copied from ...
4
votes
0answers
89 views
SHA256 implemented in Rust
I just finished making an implementation of a SHA256 hashing function (https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) in Rust and I was looking for some feedback.
As far as I can tell it ...
4
votes
0answers
90 views
Improved Knuth-Morris-Pratt over a source of indeterminate length
Following the successful review of my previous implementation.
Please review my new, generic implementation of the Knuth-Morris-Pratt algorithm. Its modified to search a source of indeterminate ...
4
votes
0answers
600 views
Error handling with C-string input using get() and getline()
I've just learned the basics of c-strings and how to read line oriented input. I noticed that fail bits are set for each function. However, not every problem sends a fail bit, so I thought this would ...
4
votes
0answers
287 views
Advent Of Code 2016 Day 9 Part 1 Solution
This code gives the solution to Part 1 of this question:
http://adventofcode.com/2016/day/9
Summary: You have to find the length of the input string after using the markers to duplicate parts of it. ...
4
votes
0answers
167 views
Reduce encoded length of UTF-8 encoded Ruby string in C extension
I'm writing a Ruby extension in C. It's a string processing module working on UTF-8 encoded strings only.
One method, full_width_to_ascii!, converts full width ...
4
votes
0answers
126 views
Perform a contains-ignore-case with multiple search-tokens
I had a look on Stack Overflow etc. on how to perform a contains ignore case with n given strings. Most answers suggested using regex for this task. Although it's a valid option, I prefer doing upper-...
3
votes
1answer
74 views
strstr implementation with python and sets
Please review my strstr implementation in terms of time/space efficiency and overall readability. I am preparing for a coding assessment coming up as I am looking to pivot my career from Physics to ...
3
votes
0answers
64 views
Early Stages of floating point class template in C++
I'm currently designing a class template to represent scientific notation or a floating-point number system. There are currently 4 distinct types: BIN, ...
3
votes
2answers
69 views
I/O-TxtFile Line Distance Program
I am trying to write a lab/program that loops through a .txt input file. Reads an entire line of data as a string, then splits that string into an array delimited by a space. If there are 4 items in ...
3
votes
1answer
410 views
Longest Substring Without Repeating Characters in Scala
Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
3
votes
0answers
281 views
Finding differences in strings with Levenshtein distance and soundex
I am trying to find a way to optimize the code runtime. Improvements I have implemented include using dictionaries, removing redundancies and using str.translate.
<...
3
votes
0answers
80 views
Count number of substrings which contains particular strings
I need to count the number of substrings of s which contains both the strings a and b.
This ...
3
votes
0answers
503 views
Reverse string in Kotlin
In the question of how to reverse a string in Java, a comment mentioned that combining Unicode code points need to be taken into account.
The below code works as intended for all test cases I tried. ...
3
votes
0answers
322 views
String conversion and stream insertion of std::ratio and std::chrono::duration
I've developed a set of functions to convert a std::ratio or std::chrono::duration to a ...
3
votes
0answers
1k views
File path normalizer
I recently wrote a file path normalizing function, with normalizing a pure lexical process. This means the function is unaware of the filesystem, and would not for instance consider symbolic links or ...
3
votes
0answers
50 views
Multiple parsers for keywords in strings
I'm writing some code that parses strings, often using simple keywords. On parsing, the code performs various actions, such a printing a response, running functions etc. and it keeps track of whether ...
3
votes
0answers
222 views
Fastest way to build string feature vectors Python
I have a list of strings to search along with a list of words and want to produce boolean feature vectors indicating presence of each word within the strings. What is the fastest way to build these ...
3
votes
0answers
552 views
Hackerrank: Sherlock and anagram (optimal time complexity)
Problem statement
Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings.
Input Format
First line contains \$T\$, the number of testcases. Each testcase ...
3
votes
0answers
1k views
Hackerrank: Sherlock and anagram
Problem statement
Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings.
Input Format
First line contains \$T\$, the number of testcases. Each testcase ...
3
votes
0answers
223 views
Converting a sentence string to a number in Scheme
I wrote a scheme procedure that converts strings such as "Two hundred and fifty" into a number like "250" that I can use in math calculations (It's for some Natural Language Processing project).
Is ...
3
votes
0answers
510 views
Largest common subsequence algorithm in C++
I'm relatively new to C++ and am trying to learn good programming practices and habits from the beginning. The code I wrote finds the largest common subsequence between to strings (and output the ...
2
votes
0answers
34 views
SHA-256 implementation in JS (core codes)
As told by experts, I am re-posting the code review request with the code.
Brief Description:
from outside sha256() will be called with parameter having UTF-16 character set.
then after prepareData()...
2
votes
0answers
142 views
Split a string into valid words
I am trying to solve this LeetCode question:
Given a non-empty string s and a dictionary wordDict containing a list
of non-empty words, add spaces in s to construct a sentence where each
word ...
2
votes
0answers
55 views
Function to match the case of a text as per another text
I am translating a text into another language using Google APIs.
Sometimes the translated text returned from the API does not match the case of the text provided - e.g. when translating the text "...
2
votes
0answers
33 views
Command String Parser
I'm working on a library that, in essence, splits a string at whitespace, with extra rules:
Consecutive whitespace is collapsed, and trimmed at the start and end.
Whitespace wrapped in quotes is not ...
2
votes
0answers
384 views
Rosalind - Finding a Shared Motif
Here is my attempt to implement the Ukkonen algorithm for the Finding a Shared Motif problem on rosalind.info.
The code works, it produces a correct answer. It does so in 11 seconds. I am hoping to ...
2
votes
1answer
1k views
Shortest way to form a string out of a subsequence of a string
The task is taken from LeetCode (subscription required) -
From any string, we can form a subsequence of that string by deleting
some number of characters (possibly no deletions).
Given two strings ...
2
votes
0answers
124 views
Faster way to replace strings in pandas series using dictionary in Python
I'm working with a dictionary with 11830 keys/values, that have to loop over 13905 strings, that can have up to 50 words each. My series looks like this:
...
2
votes
0answers
33 views
Finding the numerically listed string to the center algorthim
The algorithm takes input for a string's length for L, and the number of strings altogether for X. The hamming distance is for input D. Input Z calculates the exact amount of all possible characters ...
2
votes
0answers
128 views
Not a very interesting implementation of a simple substitution cipher in Python
I know this has been done before, but I needed to brush up my Python skills. Also, I intend to publicly share this code on a blog post sometime in the near future. This is also an attempt to improve ...
2
votes
0answers
61 views
Composing commands to control virtual machines
I created a function which takes some inputs and builds a specific set of strings. The function is working as intended, however I can't help thinking how ridiculous it looks every time I see it. I ...
2
votes
0answers
38 views
Multilang sentence to N-gram
Task: Transform sentence to n-gram and remove all punctuation
Tests:
Input: ngram('Name, + other ~ name!', 1)
Result: ['Name', 'other', 'name']
Input: ngram('Name, + other ~ name!', 2)
...
2
votes
0answers
114 views
Knuth Morris Pratt substring search algorithm
Below you can find a Kotlin based implementation of the Knuth-Morris-Pratt substring search algorithm.
...
2
votes
0answers
1k views
minimum window subsequence leetcode dynamic programming solution
Given strings S and T, find the minimum (contiguous) substring W
of ...
2
votes
0answers
107 views
Simple, semi-function string implementation in C++
I have three files: the header, implementation and a test driver. This is a general purpose code review, so I would appreciate any feedback on anything from style to design to inaccuracies in my logic ...
2
votes
0answers
2k views
Nand2Tetris Hack Assembler
Now I know the same type of question (same task) has been asked on this site before, but I recently wrote my C++ implementation of the Hack Assembler from the Nand2Tetris Chapter 6 course (defined ...
2
votes
0answers
96 views
anagramDetection.js
A function that accepts two parameters, a parent and a child string. Determines how many times the child string - or an anagram of the of the child string - appears in the parent string.
...
2
votes
0answers
99 views
With 2 sets of strings, find a string that can be constructed from either set
Given the following sets of strings:
are yo
you u
how nhoware
alan arala
dear de
I need to find a sequence that can be constructed by concatenating the strings ...
2
votes
0answers
857 views
KMP string-matching algorithm implementation
This is Knuth-Morris-Prat algorithm implementation to check if a pattern is present in a larger text, and if it does the algorithm returns the start index of that pattern, else -1. It starts off by ...
2
votes
0answers
73 views
Subtraction in a spreadsheet column numbering scheme
The idea of the algorithm is to decrease a number from a word.
Is there a better way to write this algorithm?
limitiation:
it is important to decrease with a limit, if BB is the word we
decrease ...
2
votes
0answers
440 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 numbers,...
2
votes
0answers
190 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 ...
2
votes
0answers
87 views
Storage policies
I often come across situations where a library component needs to buffer a large amount of data for later processing. The problem is that at the design stage a choice needs to be made as to whether to ...