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
9 votes
7 answers
2k views

Remove all unwanted characters from a string buffer, in-place

The following code was written with the intent to be as efficient as possible, where efficiency includes speed of execution, memory usage, and lines of code, all in support of the primary design ...
user avatar
  • 328
2 votes
1 answer
155 views

Find if a dataset of words contains any words containing all vowels by using exactly 5 calls to str_detect

Take the words dataset from stringr. An R4DS exercise challenges the reader to check if there are any words in that dataset that ...
user avatar
  • 63
2 votes
1 answer
62 views

Compare strings to markup commentary in main text

...
user avatar
  • 321
3 votes
3 answers
556 views

Longest common prefix for set of strings

Question: Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example : ...
user avatar
4 votes
3 answers
86 views

Pythonic way of removing one word entries from compound list

Assume a multi-line file (myInput.txt) with lines comprising one or more words. ...
user avatar
1 vote
1 answer
53 views

Create a random string with a set prefix [closed]

I was curious on how I could create a random string and have it have a set prefix. Lets say, as an example, 3456. This question is more referring to how I would join two strings together, my prefix ...
user avatar
4 votes
4 answers
1k views

Efficiently splitting a string in C++

I've made a splitString() function which receives a character and a string and returns a vector<string> containing all the ...
user avatar
  • 85
1 vote
2 answers
625 views

InterviewBit Problem: Stringoholics

I am trying to solve https://www.interviewbit.com/problems/stringoholics/ InterviewBit problem. Problem Statement: You are given an array A consisting of strings made up of the letters ‘a’ and ‘b’ ...
user avatar
2 votes
1 answer
57 views

String formatting

My requirement is to format the input values to a particular format as "##.###/##.###" Example - My input value can have alphabets, alphanumeric, numeric Expired -- > if alphabet, output ...
user avatar
1 vote
1 answer
76 views

Go Lang custom convert array into string with two separators

This is my custom function to join strings from an array into one string. We can provide normal separator and the last one. ...
user avatar
  • 11
4 votes
3 answers
236 views

Censoring emails in Java

I'm working on a simple method that would censor emails (GPDR stuff) so they won't show the full name of a user, with 1st character, optional dot, 1st character after the dot and whatever is left ...
user avatar
1 vote
2 answers
474 views

URLify a given String - replace spaces with %20

I have written a code to replace all spaces in a String with %20. ...
user avatar
  • 113
1 vote
1 answer
42 views

C scrabble counter with piping input

I want to start making some command line programs in C, this is a fork of something else I made but is more suitable to this site. My big question is there a better way to pipe commands? I think the ...
user avatar
  • 35
3 votes
3 answers
97 views

C string parser criticism

I have written a program to parse a string depending on the string the user provides. Any advise/criticism is appreciated. ...
user avatar
  • 403
-1 votes
1 answer
92 views

Scanning multiple strings in one line to a pointers array in C [closed]

I'm trying to write a code for a function that takes an empty array of pointers and its length n. And scans n strings of max length of MAX_LEN (a defined constant) until a new line is given by the ...
user avatar
  • 171
2 votes
1 answer
32 views

C code to reset all usb devices (because ubuntu laptop disables usb mouse after sleep)

I don't program much in c, but cobbled together some code from different places in google. I'm sure this is backwards especially in how it works with strings and directory files. Please let me know ...
user avatar
  • 23
1 vote
2 answers
69 views

PHP strpos() as a way to implement an swear word filter

I wrote a short function that should check if user input does contain any bad words that I predefined inside $bad_words array. I don't even care to replace them - I ...
user avatar
  • 13
1 vote
1 answer
226 views

Golang - Splitting a string by a separator not prefixed by an escape string

I need to split a string by a separator but don't want to split if the separator is prefixed by the escape string. For example: ...
user avatar
  • 113
1 vote
1 answer
63 views

Unique elements, long runtime Haskell

I have two functions. Both have to have unique elements, one with Integers and the other a String which returns a list of ...
user avatar
  • 135
2 votes
2 answers
769 views

C++ overloading += operator in custom string class better implementation

I am trying to learn C++, so I started coding a custom string class (using only c-style strings) to get familiar with concepts like operator overloading etc. in the case we have a pointer attribute. I ...
user avatar
0 votes
2 answers
27 views

Abbreviating a name

This is a question from a CS diploma question set : Make a program that will create an abbreviation of any given name using the initials. For example if the name if "John Doe", the program ...
user avatar
0 votes
3 answers
197 views

My safer strcmp

If used right, strcmp is not dangerous. However the code calling it might be. Limiting the opportunity for bugs I might in large teams "dictate" some kind ...
user avatar
  • 175
4 votes
3 answers
180 views

Excel VBA code midStr() function using left and right position instead of length used with mid()

In the early days of Basic (1970's when i started coding) the midStr() function used left and right positions directly rather than left and length we now use with mid(). I always found it more ...
user avatar
  • 109
2 votes
1 answer
138 views

Parsing glider data from IGC files

I have to do a program in PHP that reads IGC files like this IGC file and gets records about the glider. For now I came up with something like this: ...
user avatar
  • 21
6 votes
2 answers
364 views

Flatten JSON to string

The code below is a Python module to flatten JSON-like structure (nested dictionaries and lists) to a single string. It also provides partial result in the form of flat list of strings. This ...
user avatar
5 votes
3 answers
110 views

C function that emulates string concatenation operator '+' in Python or Go

I'm working on a project of mine which required multiple calls to strncat(), and it came to me that it'd have been much easier if C also had something like ...
user avatar
2 votes
0 answers
82 views

Is there a better pattern to match those words with regex?

Hello StackExchange community, I am curious if there is a better solution than mine for this exercise below: Enter a regex that matches all the items in the first column (positive examples) but none ...
user avatar
1 vote
1 answer
122 views

Method encodes all less than (<) characters in a HTML string, but not the HTML tags

I am cleaning a HTML string to encode the less than sign (<) to a HTML entity (&lt;), but leaving the HTML tags as they are. An example is converting ...
user avatar
  • 113
4 votes
3 answers
981 views

Split function using C and dynamic memory allocation

I have programmed a function to split strings, and it gives the expected output. I am looking forward to write better code and I was told here is a good place to start. Here's my program: ...
user avatar
  • 41
1 vote
0 answers
65 views

A batch_recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Unwrap Level for Various Type ...
user avatar
  • 3,576
1 vote
2 answers
166 views

Read strings from a standard input, and find the most duplicated word

Write a program to read strings from standard input looking for duplicated words. The program should find places in the input where one word is followed immediately by itself. Keep track of the ...
user avatar
  • 209
3 votes
2 answers
597 views

Pluralize a string

I find that a common pattern when outputting a message is the need to pluralize a word. For example, if I need to output a count of files found I would need to write something like ...
user avatar
  • 1,423
20 votes
6 answers
4k views

Password validator

I have made a password verification "program" which takes user input and checks whether the password is valid or not. Based on that, a reply is printed. ...
user avatar
  • 303
2 votes
2 answers
63 views

Chunk a large set of characters by a specified set of delimiters and a maximum chunk size

Problem I need to be able to grab a subset of characters but ensure that each set doesn't exceed a specified limit and must end with a defined set of characters. For example, say I have an entire book ...
user avatar
0 votes
1 answer
130 views

Markdown table strings to two dimensional array converter implementation in C#

I am attempting to implement a converter which can convert List<string> type markdown table into two dimensional array ...
user avatar
  • 3,576
18 votes
6 answers
4k views

A C++ program to check if a string is a pangram

I'm new to C++ and decided to implement a simple program that checks if a string is a pangram (i.e. the string contains all the English alphabet letters). It's my first program in C++ and I have some ...
user avatar
  • 183
0 votes
2 answers
86 views

A recursive function to reverse string

Write a recursive version of the function reverse(s), which reverses the string s in place. I'm studying K&R and wrote a code for the question. ...
user avatar
  • 197
1 vote
1 answer
133 views

String tokenizer

Objective: Create a function called wordsAndSpaces that splits a string on groups of spaces, preserving each group of space characters as a single token. Example: <...
user avatar
  • 155
2 votes
1 answer
378 views

Two Dimensional Array to Markdown Table Converter Implementation in C#

I am attempting to implement a converter which can convert two dimensional array (such as string[,]) into markdown table. The experimental implementation The ...
user avatar
  • 3,576
3 votes
1 answer
47 views

Text replacement with Räubersprache ("Røversprog")

I've been toying with Haskell again and implementing a simple text replacement program that replaces all consonants c in a text by coc, i.e., inserting an 'o' in between: ...
user avatar
  • 869
0 votes
1 answer
57 views

Write a Kotlin function "commonPrefix"

Task description: Write a function commonPrefix, which takes two strings as parameter and returns the common prefix. Example: parameters ...
user avatar
  • 3,758
3 votes
2 answers
1k views

Separate an email address into its username and domain name

This is my first ever Python program and I wanted to get everyone's opinions on it. The goal of the program is to separate an email address into its username and domain name. ...
user avatar
3 votes
2 answers
140 views

Parse sequence of characters detecting formatting categories

I am a beginner coder and SonarLint tells me code is too complex. I tried recursion, iterators, slicing but had not luck making this code any simpler. The code will parse the input string to detect ...
user avatar
4 votes
2 answers
134 views

Retrieving top-level opening and closing sequences from a Python string

The problem I'm solving is a more complex version of pairing up opening and closing brackets. Instead of matching only on ([{}]), I additionally need to match ...
user avatar
-1 votes
1 answer
223 views

Finding longest word in a sentence

A problem from Coderbyte. Find the longest word in a sentence after removing the punctuations and if two or more words are of same length return the first word Below is my solution: ...
user avatar
  • 585
3 votes
1 answer
278 views

Strlen function optimization

So I'm making a strlen function and I thought I would use SIMD instructions for it. It runs fine but when comparing it to std::strlen(), it falls a lot behind. Any ideas on how to make it faster would ...
user avatar
4 votes
4 answers
954 views

Limit fgets input to up to a certain number of characters

This question is an extension of this other question from Stackoverflow. The objective is to limit the input of characters read by fgets to up to a certain number of characters. And in the following ...
user avatar
  • 141
1 vote
1 answer
113 views

Find Permutations of String in Scala

Given a smaller strings and a bigger string b, design an algorithm to find all permuta­tions of the shorter string within the longer one. ...
user avatar
4 votes
1 answer
92 views

Fold long lines (K&R2 Exercise 1-22)

Exercise 1-22. Write a program to "fold" long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your ...
user avatar
2 votes
2 answers
200 views

Numeronym generation

Problem statement I need to generate numeronyms from a string, let's say qwerty as follows: qwerty q1erty q2rty q3ty q4y Code ...
user avatar

1 2 3
4
5
58