The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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.

100 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8
votes
0answers
48 views

Checking whether a string fragment could be part of a longer UTF-8 string

Although UTF-8 validation is a common task, I'm trying to solve a slightly different task; given a string of bytes, work out whether it could potentially be a fragment of a valid UTF-8 string. That's ...
6
votes
0answers
713 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
12 views

Boyer Moore Horspood Search Algorithm in Go

I am practicing Go and try to implement Boyer Moore Horspood Algorithm in Go, It returns all ocurrance of a "phrase" in a given text. This code is working, but I would be pleased to have any feedback ...
5
votes
1answer
129 views

Search and Replace (FreeCodeCamp intermediate algorithm scripting)

I completed the challenge and passed the tests: Perform a search and replace on the sentence using the arguments provided and return the new sentence. First argument is the sentence to perform ...
5
votes
0answers
106 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
96 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 ...
4
votes
0answers
93 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 I improve? ...
4
votes
0answers
65 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
335 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
373 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: ...
4
votes
0answers
273 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
103 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
81 views

Knuth-Morris-Pratt algorithm in Java Finding substrings in a matrix

Problem Given two matrices: a pattern p and a text t. Write a program that counts the number of occurrences of ...
3
votes
0answers
60 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 ...
3
votes
2answers
59 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
0answers
108 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
73 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
345 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
258 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
732 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
198 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
355 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
112 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
144 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 ...
3
votes
0answers
497 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 ...
3
votes
0answers
46 views

Reformatting a structured string like “a-b-c|A-B-C” into “a-A|b-B|c-C”

The code below was inspired by this post in Code Review. Here is how it was first intended by its author: I have the following code that converts a string that looks like : aaa-bbb|ccc-ddd|eee-...
2
votes
0answers
94 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
32 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
67 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
0answers
41 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
31 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
53 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
1answer
58 views

Concatenating an already existing filename to create a new file

I had answered this question from stackoverlow and the code below is code that I wrote to explain to the OP a possible way to achieve what I believe they were looking for. The general idea that I ...
2
votes
0answers
41 views

vb.net Create textfile from template

What is the best approach for creating textfiles from/with a template ? Currently I just read the template from a textfile and Replace all values needed, but I don't think that this is the most solid ...
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
36 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
878 views

minimum window subsequence leetcode dynamic programming solution

Given strings S and T, find the minimum (contiguous) substring W of ...
2
votes
0answers
95 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
93 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
95 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
810 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
70 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
1answer
118 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 ...
2
votes
0answers
436 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
152 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
83 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 ...