Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
6 votes
1 answer
375 views

C++ program to format byte sequences into Python like string representations

This is a C++ program I wrote, that includes functions to convert integers to byte sequences in little endian or big endian order, and functions to convert a byte sequence to a string representation. ...
Ξένη Γήινος's user avatar
6 votes
3 answers
488 views

locale-aware trim functions for std::string

I have written the below two trim functions for std::string and std::basic_string that are locale-aware. Both trim all white ...
digito_evo's user avatar
4 votes
2 answers
650 views

Implementing strscpy(): Is using errno as a negative return value a bad practice?

strscpy() is similar to the standard strncpy() except that it always writes a valid null-terminated string (unless ...
ismbks's user avatar
  • 41
4 votes
4 answers
315 views

Implementing basename, stpcpy, asprintf, vasprintf, strchrnul, and strcasecmp

C23 standarized strdup()/strndup(), but left out stpcpy(). ...
Harith's user avatar
  • 7,334
3 votes
1 answer
48 views

Advanced String Calculator with asin, acos, atan Functions in C++

This is a follow-up question for Advanced String Calculator in C++. Considering the suggestions mentioned in MrBean Bremen's answer, I am trying to update the implementation as below. The experimental ...
JimmyHu's user avatar
  • 5,070
0 votes
0 answers
37 views

Faster method to check if a string is found inside Word Files in a directory and subdirectories

I need to check if a string is found inside a Word File in a directory and subdirectories. I have tried to use Advanced Search of MS Windows 10, to search inside ...
Peace's user avatar
  • 113
4 votes
2 answers
609 views

is_number Function Implementation in C++

I am trying to implement a function which can determine a string is a number or not. Both positive and negative integers / floating numbers are considered. The experimental implementation ...
JimmyHu's user avatar
  • 5,070
5 votes
1 answer
209 views

String character changes (case insensitive) - Go

I saw this question on one of the socials, presented as an Apple interview question. I have had to paraphrase as it was not given in text format. (Credit: Instagram @greghogg5) Given a string (S) ...
Romeo Lima's user avatar
3 votes
1 answer
164 views

Snail matrix in Java - version III (generalizing)

Once again, in the previous version, Alexander Ivanchenko helped me with his awesome answer. Now, I have improved the toString() and, also, generalized the class ...
coderodde's user avatar
  • 28.6k
8 votes
3 answers
862 views

Split String Function Implementation in Python

For learning purposes, I am trying to implement Python's built-in function split. I am new to Python, and I know that str.split ...
JimmyHu's user avatar
  • 5,070
3 votes
1 answer
85 views

Multiline string concatenation

Problem Description Printing the result of adding two numpy arrays together is very ugly. Here we will use these numpy arrays as an example: ...
mikeLundquist's user avatar
4 votes
1 answer
103 views

C - Force a macro argument to be a string literal

The requirement is to define a macro which takes a single argument that is a string literal. My first try at it was to surround it with empty string literals (I got this from Modern C): ...
Harith's user avatar
  • 7,334
5 votes
2 answers
826 views

A String View Library in C

I was recently working through the PintOS projects and became curious if there was a better way to do some string processing in C. Specifically, instead of strtok_r,...
Alex Lopez's user avatar
4 votes
2 answers
108 views

(Another) text formatting method with word wrapping in Java

Please take a look at my code for (simply) formatting/wrapping a text. Is there something to improve? Here are the properties the method should have: (updated) Every space character (i.e. ...
Tobias Grothe's user avatar
2 votes
3 answers
682 views

Step-by-step re-arranging of a string with randomized characters

A sloppy code featuring algorithms to efficiently randomize the characters of a string "Hello C" and then print out in the console the re-arrangement process for every character. ...
Edenia's user avatar
  • 1,568
5 votes
4 answers
285 views

Fizzbuzz in C sharp

I have been asked to implement this and completed that. There was also a request to apply the SOLID principles and use a CLEAN CODE approach. Write a program that prints the numbers from 1 to 100. ...
Mauricio Gracia Gutierrez's user avatar
2 votes
2 answers
145 views

A small header-only input output library

The library (inspired by stb libraries) attempts to provide some commonly used functions (reading a file into memory, determining the size of a file) that are missing from the C standard library ...
Harith's user avatar
  • 7,334
3 votes
1 answer
103 views

Read a line from a stream

Since the standard fgets() does not suffice for my use cases, as it doesn't automatically enlarge the target buffer if needed, and ...
Harith's user avatar
  • 7,334
2 votes
1 answer
109 views

Thread-safe strtok in C - version II

After improving Thread-safe strtok in C according to vnp's and Harith's nice comments, I ended up with this: Code strtok_arr.h: ...
coderodde's user avatar
  • 28.6k
7 votes
3 answers
1k views

Thread-safe strtok in C

(This post has a version II.) Since strtok is not thread-safe, I decided to practice and write a thread-safe replacement. This code and the demo runner may be found ...
coderodde's user avatar
  • 28.6k
3 votes
2 answers
169 views

Truncating/abbreviating strings in the middle with an ellipsis (…) (or other) separators with a fixed character limit

Problem For some user-facing string, I want to truncate it to some given maximum length (also useful for file name/path lengths on Windows etc.). However, I want to do it a little more elaborately ...
rklec's user avatar
  • 53
3 votes
1 answer
79 views

Fast search for the longest repeating substrings in large text (Rev.4)

This is the forth iteration of the Fast search for the longest repeating substrings in large text (Rev.3) code review. Special thanks goes to G. Sliepen who conducted all the reviews. Functional ...
Damir Tenishev's user avatar
2 votes
1 answer
107 views

Fast search for the longest repeating substrings in large text (Rev.3)

This is the third iteration of the Fast search for the longest repeating substrings in large text (Rev.2) code review. Special thanks goes to G. Sliepen who conducted the first two reviews. Functional ...
Damir Tenishev's user avatar
6 votes
1 answer
135 views

One Time Pad encryption in Python

I made this code to encrypt a string with the One Time Pad method. Is this pythonic code, and are there obvious ways I can improve? The program accepts a plaintext and can either accept an inputted ...
Vessel's user avatar
  • 133
2 votes
1 answer
96 views

Fast search for the longest repeating substrings in large text (Rev.2)

This is the second iteration of the Fast search for the longest repeating substrings in large text code review. Special thanks goes to G. Sliepen who conducted the first review. Functional ...
Damir Tenishev's user avatar
6 votes
4 answers
1k views

Automate character search in C

THE TASK We are dealing with a string of symbols and need quick responses to queries of the following types: What is the position of the k-th occurrence of symbol X in the string? Reading from ...
Wow1345's user avatar
  • 121
3 votes
1 answer
177 views

Fast search for the longest repeating substrings in large text

Is there a chance to implement the code below better with the features of recent C++ versions? Functional specification Having a large text and already built prefix array find the longest substrings (...
Damir Tenishev's user avatar
3 votes
2 answers
139 views

A simple search-and-replace algorithm

In recent times, I've been using the following algorithm repeatedly in different languages (Java, Python, ...) to search and replace strings. I don't like this implementation very much, it's very ...
Green绿色's user avatar
3 votes
1 answer
207 views

Calculate the maximum number of decimal places with which all floating point numbers can be represented in a range in C++

I'm looking for a function in C++ that can determine, how accurate all floating point numbers in a given range can be represented as strings, without the use of e.g. boost library, etc. Please take a ...
Tobias Grothe's user avatar
4 votes
2 answers
435 views

Z-Function/ Algorithms on strings. C++

The problem: Given a string s. For each i from 1 to |s|, find the number of occurrences of its prefix of length i in the string. Input: The first line of input contains an integer q (1≤q≤10⁵) — the ...
neely's user avatar
  • 43
18 votes
3 answers
3k views

trimming a string using C++20 ranges

I have a function which is supposed to trim a string by removing trailing whitespace, then exactly one instance of a fixed string, if it exists, and then any remaining trailing whitespace. It works ...
Edward's user avatar
  • 66.4k
1 vote
1 answer
71 views

String represents a road. One character travels on the road obeying the stops - Code challenge (advent.js day 5)

This is my code to solve the 5th Adventjs challenge. In that link you can read the instructions. How can I improve it? It's a bit messy... and I'm repeating some part of the code. All must be in just ...
Sofia Chardin's user avatar
3 votes
3 answers
144 views

Redouble each occurrence of char recursively, and add n

In following of this question, I would like to have a second review. The exercise is to write a recursive method that takes a String and a ...
Tobias Grothe's user avatar
2 votes
1 answer
57 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
193 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
588 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
6 votes
4 answers
639 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
  • 131
3 votes
2 answers
544 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
837 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
181 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
120 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,358
1 vote
1 answer
126 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,358
7 votes
3 answers
201 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
58 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
135 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
188 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
868 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
251 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
963 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,358
4 votes
1 answer
125 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,358

1
2 3 4 5
59