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.

Filter by
Sorted by
Tagged with
2 votes
1 answer
53 views

JS animated string builder

Today, I tried to write a simple function that would display the characters of my string one by one by iterating over a string containing the letters of the alphabet and showing the steps on the ...
Luca Natale's user avatar
1 vote
1 answer
179 views

Function that finds the exact number of times a string appears in a text

So I was tasked with providing a function that returns how many exact occurrences of attribute word appear in attribute text. The goal is for the function to be as fast as possible, and I managed to ...
Jules Raschilas's user avatar
4 votes
2 answers
535 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
4 votes
3 answers
312 views

C++ custom string class implementation

I recently had an interview where I was tasked with implementing a custom C++ string class without using the STL. The interviewer provided the function signatures and variable declarations, specifying ...
Jacob's user avatar
  • 111
3 votes
2 answers
512 views

One Piece Treasure- Find the number of palindromic substrings in a large substring

I'm trying to solve the below question: A string of characters X (all in lowercase) of length n is present. We can ask a query <...
driver's user avatar
  • 212
4 votes
3 answers
778 views

Codewars: Multiplying Polynomials

I'm trying to solve the following Kata from Codewars in Python. My code produces the desired result for all the tests, yet it is not optimal, so it takes too much time to accomplish the big tests. <...
GuntherOnFire's user avatar
-2 votes
1 answer
137 views

Design an algorithm to predict words based on a skeleton from a given dictionary

The model I'm building first selects a secret word at random from a list. The model which uses an API then returns a row of underscores (space separated)—one for each letter in the secret word—and ...
driver's user avatar
  • 212
1 vote
3 answers
96 views

Print last lines of file

Task Write a Ruby function, which accepts a path to a text file and returns a string consisting of the last n lines in reversed order, separated by commas. Example input file: ...
michael.zech's user avatar
  • 4,232
1 vote
1 answer
108 views

Function, which replaces consecutive white-space with a single white-space

Task-description: Implement a function, which returns a string with all consecutive whites-spaces replaced as a single-space. Example: "a[space][space][space]b[space][space][space]c" shall ...
michael.zech's user avatar
  • 4,232
7 votes
3 answers
174 views

C++ String Class Reimplementation

I started learning C++ about a week ago and I was hoping somebody can critique my code. I decided to implement my own basic String class just for the sake of applying all that I've learned about ...
Janriz Libres's user avatar
1 vote
1 answer
56 views

Revised C Doubly-Linked List

I have revised the implementation I originally posted here. Thank you all who responded; I took your comments to heart. Please let me know if you have any additional feedback. Here are some notes to ...
user129393192's user avatar
2 votes
3 answers
124 views

Automate the boring stuff with python - Comma Code v2

This is the second version of code reviewed earlier. Comma Code Say you have a list value like this: spam = ['apples', 'bananas', 'tofu', 'cats'] Write a function ...
Jarne Vercruysse's user avatar
1 vote
3 answers
142 views

Automate the boring stuff with python - Comma Code

Comma Code Say you have a list value like this: spam = ['apples', 'bananas', 'tofu', 'cats'] Write a function that takes a list value as an argument and returns a ...
Jarne Vercruysse's user avatar
5 votes
1 answer
789 views

Speed up strlen using SWAR in x86-64 assembly

The asm function strlen receives the link to a string as a char - Array. To do so, the function may use SWAR on general purpose register, but without using ...
HeapUnderStop's user avatar
5 votes
1 answer
132 views

string_view tokenizer function template

Below is a function template that tokenizes a given std::basic_string_view using a given delimiter and assigns the tokens to a buffer (via a ...
digito_evo's user avatar
9 votes
2 answers
889 views

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Task description: Write a function, which counts the letters, spaces, number and special characters in string. My implementation: ...
michael.zech's user avatar
  • 4,232
4 votes
1 answer
108 views

Is Palindrom-function in Swift

Task is simply to write the classic isPalindrom-function. Here's my implementation: ...
michael.zech's user avatar
  • 4,232
1 vote
1 answer
209 views

Replacing NOUNS, VERBS, ADJECTIVES in a text file with input words

I've written code for a program that reads a text file, checking if there's any capitalized parts of speech of specific types (noun, adj, verb, adv) in the text and replace them with the user's chosen ...
Nova's user avatar
  • 113
6 votes
1 answer
345 views

Swift-function, which checks if all letters in a string are unique

The task is writing a function, which checks if a string contains only unique characters. Means: is each character is included only one time. Here's the solution, I have developed: ...
michael.zech's user avatar
  • 4,232
2 votes
2 answers
115 views

Swift-function, which counts all occurrences of a character within a string

I wrote this function, which (shall) count all occurrences of a specified character within a given string. ...
michael.zech's user avatar
  • 4,232
4 votes
1 answer
82 views

Remove smiles from string in-place

I have a coding task. Remove smiles from string in-place. Smile is a set of characters starting from ':' and ending with one or more brackets ')' or one or more brackets '(' Example ...
mascai's user avatar
  • 397
6 votes
3 answers
566 views

Recursive function for creating a cookies string

I've created the following function that creates a cookie string for passing to cURL. It can take a nested array or object of key-value pairs. It can either create nested cookie values as JSON, or ...
Jodes's user avatar
  • 340
4 votes
4 answers
1k views

Matching words from a text with a big list of keywords in Python

I implemented the following code to retrieve medication names from a given text (prescription_text in the code). It works by matching words in the text with a list ...
cuzureau's user avatar
  • 181
7 votes
1 answer
329 views

piglatin exercise in rust

This is my attempt to make the exercise suggested at the end of this chapter of rust's official tutorial ...
JoulinRouge's user avatar
7 votes
4 answers
426 views

Separating a String of Text into Separate Words in Python

Occasionally, we want to do a rudimentary parsing on English text; we separate the text into separate words. ...
Samuel Muldoon's user avatar
7 votes
1 answer
323 views

pure Bash way to trim

How can I improve this? I added the while read loop to handle preceding newlines. ...
Andrew's user avatar
  • 75
0 votes
0 answers
64 views

Print columns of text without hard coding the width (attempt 3)

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
4 votes
1 answer
261 views

Print columns of text without hard coding the width (attempt 2)

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
3 votes
1 answer
103 views

Print columns of text without hard coding the width

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
4 votes
1 answer
599 views

Basic recursive descent parser in C

The purpose of this code is to evaluate simple integer expressions that make use of the C arithmetic and bitwise operators while respecting C operator precedence and parenthesis. I wrote this code ...
user16217248's user avatar
12 votes
10 answers
2k views

Trim leading/trailing space in a string

I'm practicing C and wrote a function to trim leading/trailing spaces in a string: ...
roadsidejesus's user avatar
4 votes
4 answers
2k views

A function that uses a regex to parse date and time and returns a datetime object

The code works, but I think can be simplified, I don't know which specific steps, but my version seems to me quite complicated I build a function that takes a specific string format and returns a <...
Andrea Ciufo's user avatar
3 votes
2 answers
188 views

Print decimal integer

This is an x86-64 Linux program to print a non-negative decimal integer. I would appreciate any simple optimizations for size and readability. I am aware that division by a constant is usually done by ...
qwr's user avatar
  • 1,016
2 votes
1 answer
65 views

Do a thing with a derived string for a number of strings

I feel this should be possible more concisely, less code repetition, with a loop and a two-dimensional array or something. But not sure how exactly. Any best practice for review? ...
Lecker Kebap's user avatar
5 votes
1 answer
1k views

String literals concatenation with support for dynamic strings

I have implemented a function to concatenate string literals at compile time. Basic requirements: Very simple API. Can be used as a one-liner. Must accept variadic string literals. Highly optimized ...
Sergey Kolesnik's user avatar
1 vote
2 answers
105 views

Optimizing - formatting a person's name

I need to take a user's name and format it 'lastName, firstName middleName'. If firstName and middleName are not present then the comma should not be included with lastName. Below is what I came up ...
Samuel's user avatar
  • 21
4 votes
1 answer
445 views

C++ String Conversions using Iconv

Since charset conversions is so darn badly implemented and most standard options are deprecated I recently wrote a wrapper around iconv that converts from system narrow / multibyte character set to ...
rioki's user avatar
  • 462
2 votes
3 answers
72 views

Resizable string object

...
John doe's user avatar
6 votes
3 answers
439 views

Reversing words of a string without using inbuilt functions

I was wondering if I could reverse a string without using collections and in-built functions of string, Please do add your thoughts on the approach and if possible do share your way of the solution. <...
CM_2020's user avatar
  • 61
2 votes
1 answer
134 views

Clean up improperly formatted phone numbers

This is a problem from Exercism here, the goal is to clean up badly formatted phone numbers. The rules are: If the phone number is less than 10 digits assume that it is a bad number If the phone ...
Josh Friedlander's user avatar
3 votes
1 answer
306 views

High performance 3 Way Quick Sort Implementation

My implementation of 3 way quick sort for strings. It supposed to sort very large set of 800,000,000 objects. This is why I added ...
Nick's user avatar
  • 1,480
3 votes
1 answer
317 views

SImple Inverted Index

This is a simple inverted index I made. The goal is to: Read set of text files from a directory, docs Tokenize them Normalize the tokens by removing punctuation ...
iluvfugu's user avatar
0 votes
1 answer
159 views

Short Text Pre-processing

For educational purpose I am preprocessing multiple short texts containing the description of the symptoms of cars fault. The text is written by humans and is rich in misspelling, capital letters and ...
Andrea Ciufo's user avatar
-2 votes
1 answer
248 views

Number Plate Generation Program

I wrote a number plate generation program. The program generates number plates for a car registered with a specific Memory Tag and on a specific date. Number plates use the following format: (2 letter ...
kmvfkmfv's user avatar
1 vote
2 answers
249 views

Replacing banned words from a given text

The following algorithm is used to find a word from Blacklisted words in a string (called text) and replace these words with censored text, as shown in the example. Example: ...
TomaszOleszko's user avatar
0 votes
1 answer
69 views

Convert strConflictedYesReviewers data into a single object which is grouped by ownerid and make array of opportunityid

I get a dynamic string(strConflictedYesReviewers) which contains multiple user recordswhere each record is separated by semicolon and then each record represents ownerid and opportunityid separated by ...
Karim Ali's user avatar
  • 105
1 vote
3 answers
73 views

FileIO lines to String Converter

I think I made a good FileIO object because I can simply copy-paste whenever I need, however I wonder How I can improve my code. This code takes file path of the target file and turns every line to ...
ekan123's user avatar
  • 13
2 votes
4 answers
464 views

Creating storage path for file from first characters of a hash

I made the following function to create the storage path for files from the the first 5 characters of the file's hash: ...
pileup's user avatar
  • 361
5 votes
4 answers
631 views

An immutable C++ string with ref-counting

Class intended to be used as main type in a key-value database where keys and values are strings. Searched features: It is a const char * Behaves like a ...
Gerard Torrent's user avatar
1 vote
3 answers
169 views

Convert camelCase function name to snake_case

I have the following code: ...
TomS's user avatar
  • 11

1
2 3 4 5
59