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
5
votes
1answer
85 views

Algo to return a vector of available time slots for scheduling a meeting between two persons

There are 2 persons and their already booked meeting schedule is given and also time bound for both the person is given. Now, we want to schedule a meeting between them in an available time that suits ...
1
vote
3answers
65 views

Validating an integer with affixes in compile-time or runtime

I'm implementing a function called is_proper_integer that will check the string whether it is a valid integer literal by borrowing the idea from C++ grammar. ...
7
votes
1answer
138 views

Create tweet threads from String in Java

I recently got this question in an exam, this is how I implemented, it is working fine. However, I would like to know if the code can be improved, as I think it for sure needs to be improved. The ...
1
vote
2answers
81 views

Function to skip characters

A very simple function that can be used such that it returns a pointer to the first character on which func returned 0. However, ...
2
votes
3answers
173 views

string to double

I'm trying to write a function to replace the standard std::stod(...). I want to parse the following valid inputs: ...
3
votes
1answer
74 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
155 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 ...
0
votes
2answers
97 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. ...
10
votes
4answers
3k 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
58 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 ...
1
vote
1answer
165 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
87 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
58 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
119 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
570 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
81 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
995 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
103 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
118 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
36 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
126 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
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 ...
2
votes
1answer
109 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
55 views

Compare strings to markup commentary in main text

...
3
votes
3answers
371 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
84 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
35 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
570 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
429 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
51 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
65 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
179 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
271 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
39 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
69 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
56 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
29 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
58 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
64 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
60 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
383 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
182 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
135 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
102 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
275 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
105 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
57 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
106 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
648 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: ...

1
2
3 4 5
56