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
1
vote
0answers
14 views

garbage string remover with array or object input

This is the second time I am writing any practical JavaScript so it is pretty likely that I have messed something up. I am beginner, so just need a piece of advice before sharing the code: Do I need ...
4
votes
1answer
115 views

A different approach to string pattern matching algorithm

Although there exists the most efficient "Knuth-Morris-Pratt" algorithm of string pattern matching. I tried to achieve the same result with a different approach. But I am not sure about it's ...
-1
votes
2answers
79 views

Find first non repeating char in a string

This is LeetCode question 387 if anyone is interested. The task is to accept a string and find the first char that appears only once, and return its index. If no char appears only once then return -1. ...
9
votes
4answers
2k views

First non-repeating Character, with a single loop in Python

I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop. My thinking is, it would be easy to tell you what ...
1
vote
2answers
44 views

Extracting items from comma/semicolon-delimited strings, discarding parts after a hyphen

New Scala dev here. Is there a more idiomatic or efficient way to accomplish this in Scala? Given a list of the following strings, I need to obtain the unique 'main parts' once any parts including ...
0
votes
2answers
98 views

Fastest string search algorithm

I have invented the fastest string search algorithm. Can someone prove that it is not fastest? I am not considering worst case scenarios. The algorithm can be found here: https://sourceforge.net/...
1
vote
2answers
83 views

Check URL for keywords [closed]

I'm looking at improving my PHP knowledge and wondering if anybody has any tips on improving and optimising my function below? ...
0
votes
1answer
55 views

Rabin karp substring search

Below is the Rabin Karp implementation. I am not so sure about it, and there is no where that I can check whether this code really works or not. It will most helpful for extra set of eyes if whether ...
2
votes
2answers
90 views

Counting uppercase and lowercase characters in a string

I created two programs (one with JAVA8) to calculate the total count of uppercase and lowercase characters in given String. After checking the execution time JAVA8 is taking longer execution time than ...
5
votes
2answers
503 views

Replace n or all occurrences of substring in C

I wrote this code as an answer to a question. But I'd like you to have a look at it. This post is basically a copy of the answer I posted. The code does no error checking. It assumes that the output ...
-2
votes
1answer
66 views

Find repeating pattern in a string

I have written a C function that finds the shortest substring that can be repeated to produce the entire string. input: abcdeabcde result: ...
4
votes
8answers
897 views

Are two strings anagrams?

My code passes all the given test cases. I would like to know a better way to to write the code. Such as a more efficient algorithm for checking if two strings are anagrams. ...
2
votes
3answers
97 views

Check if array of strings have the same substring

I have a list of files that conform to a template like this: XXX_{project}_{variation}---XXX.html and ...
1
vote
3answers
111 views

Run-length coder

I have this code, which counts only adjacent letters in a string and returns the count of each letter. ...
1
vote
1answer
35 views

tokenize char array with PolarSSL library

I'm trying to perform a decryption operation using RSA. I'm using the PolarSSl library. I have a char array key[] that contains RSA private key like the following, <...
1
vote
2answers
48 views

A [non-destructive] better (not really) `strtok` function

The first time I used strtok, it felt, well, weird. But after a while, I became quite used to it. In a way it was simple. Soon after reading a bunch of Stack ...
8
votes
7answers
1k 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 ...
2
votes
1answer
94 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 ...
2
votes
1answer
53 views

Compare strings to markup commentary in main text

...
3
votes
3answers
329 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 : ...
4
votes
3answers
82 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. ...
1
vote
1answer
32 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 ...
4
votes
4answers
193 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 ...
0
votes
2answers
273 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’ ...
2
votes
1answer
45 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 ...
1
vote
1answer
62 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. ...
4
votes
3answers
152 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 ...
1
vote
2answers
141 views

URLify a given String - replace spaces with %20

I have written a code to replace all spaces in a String with %20. ...
1
vote
1answer
32 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 ...
3
votes
3answers
68 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. ...
-1
votes
1answer
53 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 ...
2
votes
1answer
26 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 ...
1
vote
2answers
54 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 ...
1
vote
1answer
52 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: ...
1
vote
1answer
55 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 ...
2
votes
2answers
183 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 ...
0
votes
2answers
25 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 ...
0
votes
3answers
173 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 ...
4
votes
3answers
115 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 ...
2
votes
1answer
87 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: ...
6
votes
2answers
197 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 ...
5
votes
3answers
100 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 ...
2
votes
0answers
36 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 ...
1
vote
1answer
98 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 ...
4
votes
3answers
362 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: ...
0
votes
0answers
33 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 ...
1
vote
2answers
79 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 ...
3
votes
2answers
160 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 ...
20
votes
6answers
3k 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. ...
1
vote
1answer
32 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 ...

1
2 3 4 5
55