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
1answer
25 views

User-friendly string struct and utility functions

Created a new typedef and functions supporting it, making it user-friendly [specifically programmer-friendly]. What does the code do? It makes users [programmers] easy to deal with strings as most ...
2
votes
1answer
89 views

String Manipulation: Given two operations on a character 'A', Copy and Paste, find the minimum number of operations to produce a string of length 'N'

I have a solution to the following question which seems straightforward enough. However, I feel as if I am missing something. The question: Objective: You have given a character ‘A’ which is already ...
3
votes
3answers
80 views

Convert program arguments to std::wstring

Due to recent need I wrote a simple main function that has the goal to convert the C-style strings and arrays into a more STL-style. Then because I also had a need ...
2
votes
3answers
101 views

Convert string to integer and catch errors

I have attempted [and made one] function to convert string to integer and catch errors in pure c Working method The whole working method is present in code itself The header file The str2num.h here:- <...
2
votes
1answer
58 views

replace substrings from within Hebrew text

I have a string of Hebrew text which also contains":", "-", & "|". Attempting to replace "-", "|", and ":" with a space. How can I do ...
2
votes
1answer
32 views

word frequency distribution

wordList is an array of non-empty strings ("words"). The following code I have written with the purpose of obtaining a Map, containing the unique words ...
12
votes
4answers
2k views

Comma Code, Project from "Automate the Boring Stuff with Python"

I'm a newbie. I'm at Chapter 4 of Automate the Boring Stuff with Python. Comma Code Say you have a list value like this: ...
2
votes
2answers
47 views

Find the 'n' most frequent words in a text, aka word frequency

I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. This challenge is called "Word Frequency", and is based on the Rosetta Code's entry of the same name. The ...
5
votes
3answers
1k views

FizzBuzz, but with provided start and end of sequence, results stored in array, and a separate function to convert integers to strings

To learn C, I'm doing the traditional FizzBuzz challenge with extra restrictions: The start and end of sequence is provided by the user Instead of directly printing the results, the results must be ...
0
votes
0answers
30 views

Finding longest palindromic substring in a string (gives TLE on leetcode)

I'm solving the Longest Palindromic Substring problem on LeetCode. And here's my final submission: ...
2
votes
3answers
58 views

Phrase to acronym in C from exercism.io

I am learning C and doing challenges like those found on exercism.io and the various data structure & algorithm sites. I have a sense that while this works and it makes sense to me that it can be ...
6
votes
2answers
145 views

A string separator that doesn't separate if in quotes

The sep function separates string by the characters of seps, but it escapes the separates ...
0
votes
0answers
25 views

Batch installing packages script in Octave

I am attempting to write a light script to deal with multiple package installation in Octave. The available packages can be checked in Octave Forge or wikipedia. For example, if the packages ...
2
votes
2answers
86 views

Algorithmic Efficiency: GetShortestUniqueSubstring implementation

I came upon this Youtube video and the problem they discussed piqued my interest, so I decided to take a stab at it. Below is the question: Given an array of unique characters ...
2
votes
0answers
22 views

zsh function for shrinking $PWD with $HOME replacement

I wanted a $PWD shrinking for my $PROMPT with the following requirements: $HOME is replaced ...
1
vote
2answers
77 views

Is there a way to simplify getting the character that appears the most in a collection with Linq?

I have a collection of strings, all of which are three characters in length: ...
1
vote
1answer
27 views

Convert string to object array javascript

I want to convert string to object array. Suppose I have following string. const str = "someValue,display"; I want to convert it like following. ...
2
votes
1answer
67 views

Grouping anagrams together from a string array

I wrote this code in c#. It is a question from LeetCode, number 49. Given an array of strings, group the anagrams. The examples it gives are: ["eat","tea","tan","...
1
vote
2answers
46 views

Word frequency finder

Challenge: find the top three most frequently used words in a string. Only imports from the base package are allowed (source: codewars) I'm looking for feedback on (...
-1
votes
1answer
54 views

Better way to format a query string in Java

description I'm using influxDB, I need use Java to generate a query command. The TestingTag struct maybe missing 0-3 fields. code: ...
1
vote
1answer
59 views

Improving poor man's translations mechanism in c++98 program (follow-up)

As a follow-up to this question that was an attempt to add basic translation capabilities in an old c++98 program for the sake of the community, I'm posting here the first iteration of my code after ...
2
votes
3answers
77 views

Batch extracting differences between two images with enhancement using opencv

I am attempting to extract the absolute differences image between two input images and then enhance the intensity (brightness) channel in HSV color space with the given times. The workflow is like ...
0
votes
1answer
106 views

Improving poor man's translations mechanism in c++98 program

In order to add basic translation capabilities in an old c++98 program I've come up to a basic and shameless code summarized by this snippet: ...
1
vote
2answers
155 views

Parsing words from string

I am learning Java, so I am beginner. I know I can do this with split function but I want to improve my algorithm knowledge. I will be glad if you help me. Thanks. inputStr variable is contains the ...
1
vote
1answer
74 views

Replacing a char in the file name

I am formatting my TV series archive and can not do one by one. I wrote this code and it's working like what I want. I am a beginner and want to improve my knowledge of algorithm. What can you ...
5
votes
1answer
78 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
60 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. ...
6
votes
1answer
107 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
78 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
162 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
70 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
143 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
92 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
55 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
144 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
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
99 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
528 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
75 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
964 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
102 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
115 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
63 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
97 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
54 views

Compare strings to markup commentary in main text

...
3
votes
3answers
349 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 : ...

1
2 3 4 5
56