Skip to main content

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
140 views

How to refactor this (sort of) getline implementation?

Goals: Create a function char *get_next_line(int fd) such as: Repeated calls (e.g., using a loop) to your get_next_line() ...
ismbks's user avatar
  • 63
6 votes
1 answer
789 views

Basic C++ implementation of linux wc command

I am working on the Build Your Own wc Tool coding challenge in C++. I have a working implementation that seems to match the output of the wc command for different ...
Ganesh Tata's user avatar
7 votes
2 answers
931 views

Dynamic Arrays with Count / Capacity in C

I write in C for several projects (e.g. learning / teaching, coding competitions, data processing) and frequently need arrays (e.g. strings) with fast appending / concatenation / reversing. I've ...
Justin Chang's user avatar
  • 2,367
3 votes
2 answers
300 views

A View over java.lang.String - improved take II

(This post elaborates on A string view over a Java String.) This time, I have incorporated both the great answers in the previous iteration: https://codereview.stackexchange.com/a/293506/58360 by ...
coderodde's user avatar
  • 29.8k
5 votes
2 answers
544 views

A View over java.lang.String

(This post has continuation at A string view over a Java String - improved take II.) This time, I have a simple string view class for faster operation on substrings in actual string objects: ...
coderodde's user avatar
  • 29.8k
8 votes
3 answers
1k views

C - mini string lib

I'm currently going through nand2tetris, mainly as an excuse to learn C via writing some non-trivial programs. As I've already done it in python, I've began to 'port' over some of the python features ...
arm93's user avatar
  • 431
4 votes
2 answers
90 views

Parsing strings indicating duration in seconds (e.g. "60", "60s", "1m", etc.)

This is a simple function that accepts a null-terminated string that represents a non-negative number of seconds. It can optionally end in the suffix "s" (seconds, default), "m" (...
xiazhu's user avatar
  • 41
2 votes
2 answers
190 views

Byte Pair Encoding Compression in C89

This is a small project to implement Philip Gage's Byte Pair Encoding compression for the purpose of learning C. In particular, it's written in C89 for fun as that's what would've been contemporary (...
qwr's user avatar
  • 1,184
-1 votes
4 answers
243 views

strncmp_in_set(): like strncmp(), but compare characters only in a given set

I want a function like strncmp() except that it only compares characters in a given character set. Given: ...
Paul J. Lucas's user avatar
3 votes
2 answers
529 views

Left zero-padded string in C++

For a very specific usecase, I need a special version of a string, which is not only zero-terminated, but also begins with '\0'. So, the string should look like this in memory: ...
user avatar
4 votes
4 answers
154 views

Reversing string in PHP

I got this task to evaluate my knowledges in PHP. I was asked to avoid using functions like strrev() or array_reverse(). ...
user avatar
3 votes
1 answer
92 views

Build a dictionary from a string by the extraction of data from all the pairs <TAG|VAL> contained inside the string and clean string from TAGs

I have written code to manage a string and retrieve from it a dictionary which must contain pairs key-value dependent from the string. To be more clear I'll show ...
User051209's user avatar
8 votes
3 answers
2k views

is_decimal Function Implementation in C++

This is a follow-up question for is_number Function Implementation in C++. Considering G. Sliepen's answer and Harith's answer, I want to focus on decimal number here, therefore, ...
JimmyHu's user avatar
  • 5,510
0 votes
1 answer
50 views

Optimize for compute/timespace - substring matching STD pk / sk format

BUSINESS CASE For users of my application I need to manage a granular list of grants. I'm using an aws dynamodb backend with lite Single Table Design (STD) strategies. A common syntax for STD keys ...
Jamie Marshall's user avatar
7 votes
8 answers
2k views

Convert string name to uppercase

As part of an assignment, I wrote this helper function to convert a specified name to a required format. This function simply converts a string in the format "this-string" to "This ...
Linny's user avatar
  • 10.4k
6 votes
1 answer
388 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
508 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
3 answers
738 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
  • 63
1 vote
0 answers
53 views

Emulating C23's QChar * behavior for basename and strchrnul

To quote @Lundin from What is C23 and why should I care?: Bug fixes for a lot of library functions (search functions in particular): we can now pass a const-qualified pointer parameter to a library ...
Harith's user avatar
  • 9,777
4 votes
4 answers
344 views

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

C23 standarized strdup()/strndup(), but left out stpcpy(). ...
Harith's user avatar
  • 9,777
3 votes
1 answer
61 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,510
0 votes
0 answers
54 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
691 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,510
5 votes
1 answer
238 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
176 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
  • 29.8k
9 votes
3 answers
884 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,510
3 votes
1 answer
92 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
191 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
  • 9,777
5 votes
2 answers
844 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
124 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
690 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
313 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
151 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
  • 9,777
3 votes
1 answer
118 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
  • 9,777
2 votes
1 answer
117 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
  • 29.8k
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
  • 29.8k
3 votes
2 answers
215 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
  • 63
3 votes
1 answer
99 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
136 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
143 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
  • 335
2 votes
1 answer
108 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
197 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
151 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 grün 绿色 vert зеленый's user avatar
3 votes
1 answer
225 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
472 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.6k
1 vote
1 answer
72 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
156 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
58 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
2 3 4 5
60