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
8 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 ...
-1
votes
1answer
36 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: ...
4
votes
2answers
3k views

Spell Checker program using dictionary implementation

This is a small program written for a small assignment to check spelling. The assignment asks for the following output: A list of words that are misspelled in the file A count of the ...
1
vote
1answer
39 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. ...
4
votes
4answers
119 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 ...
3
votes
1answer
69 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 ...
20
votes
4answers
70k views

Flattening a dictionary into a string

Given: k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999} I want to flatten into the string: ...
6
votes
2answers
7k views

Reformatting a date from YYYY-MM-DD to MM/DD/YYYY

In this small bit of JavaScript, a date is passed in as YYYY-MM-DD. It's formatted like this to be passed to the backend system. On the front end, we need to ...
7
votes
3answers
8k views

Removing Asterisks and neighbors from a string

I am going through the CodingBat exercises for Java. I got to this problem: Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its ...
2
votes
1answer
1k views

Shortest way to form a string out of a subsequence of a string

The task is taken from LeetCode (subscription required) - From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). Given two strings ...
2
votes
2answers
45 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 ...
2
votes
1answer
44 views

Javascript. Reverse order of words in string, but not special characters

Hello I am hoping someone can provide me feedback on my solution to this prob. If there are additional edge cases I should consider etc. Thank you! The question: "Given a sentence with a set of ...
0
votes
2answers
33 views

How to use string constants correctly

I often get into the dilemma of how to use string constants, this is the way I use now: ...
4
votes
5answers
219 views

Consecutive whitespace reduction

I pursued an according algorithm with an absolute best performance, the following class embodies the solution. Any comment is welcome. ...
-1
votes
1answer
24 views

c++ convert all letters in the following text to uppercase and replace all vowels with the '#' character different format from last [closed]

how what am i supposed to make cout so the changes i make show up as the out put because putting a just shows the original string ...
4
votes
6answers
4k views

Aho-Corasick for multiple exact string matching in Java

I have this program that compares performance of two algorithm for multiple exact string matching: Given a set of patterns and the text, find in the text all occurrences of any pattern. For example: <...
6
votes
3answers
531 views

Generate random string to match the goal string with minimum iteration and control statements

The following is my python code to find the number of iterations needed to generate random string iteratively to match the input string. Here I have repeated a similar kind of for loop in both the ...
8
votes
4answers
4k views

Hacking a SecureString based on std::basic_string for C++

Inspired by reading "How-to write a password-safe class?", I tried some clever (or dumb-fool) hack to create a widely-useable secure string using the ...
3
votes
1answer
87 views

Substring search in Java

I am trying to make an algorithm that will find the index of a given substring (which I have labeled pattern) in a given String (...
1
vote
1answer
61 views

A Paragraph Merger with Removing Overlapped Duplicated Lines in C#

I am trying to make a paragraph merger that takes multiple paragraphs and output a concatenated result with removing the duplicated overlapped lines due to redundancy. Each input paragraph is with the ...
1
vote
2answers
61 views

C text word-wrapping

I'm writing a program that has the possibility of outputting a large amount of text on a single logical line to the console. In that scenario, I would like to wrap the text at word ends so that words ...
7
votes
2answers
97 views

Method to randomise a string's case

I'm an amateur at programming and have created the following method with which I pass a lowercase string with the idea it is then returned either in it's original ...
0
votes
2answers
44 views

Identifying indices of non-delimited characters in a string, supporting greater than 1 length of delimiters

The code below takes a string that potentially contains a true match for a delimiter. There can be multiple delimiters located anywhere in the string. We need to obtain the indices that are not a ...
22
votes
5answers
24k views

Split a string into chunks of the same length

Inspired by this question in chat Is there an easy way in .NET to split a string into an array by pulling chunks of the text in. I.e. I have an 18 character string I would like in 3 6-character ...
2
votes
1answer
51 views

Extract string between first occurring set of parenthesis

I have this function and need to refactor it Please refactor the code below to make it more concise, efficient and readable with good logic flow ...
3
votes
1answer
76 views

strstr implementation with python and sets

Please review my strstr implementation in terms of time/space efficiency and overall readability. I am preparing for a coding assessment coming up as I am looking to pivot my career from Physics to ...
41
votes
4answers
11k views

A lightning-fast StringBuilder

In the process of trying to build a serializable data structure, I found myself building large strings, which gets very slow because VBA copies a string every time concatenation is performed. To ...
2
votes
2answers
74 views

Replace string based on multiple rules, don't replace same section twice

Given a 2-column CSV dictionary file that contains translation of certain words, this c# code needs to replace the first occurrence of a word in the dictionary. Once a segment of string has been ...
3
votes
1answer
59 views

A Sub-string Extractor Implementation with Given Vocabulary Words in Java

This is a follow-up question for A Sub-string Extractor Implementation with Specific Keywords in Java. As AJNeufeld's answer mentioned, the test case ...
6
votes
0answers
133 views

Generate unique random strings considering collisions

I'm coding a random strings generator. It's working, but I'm not sure if this is efficient. ...
7
votes
3answers
4k views

Word Separator and Pig Latin Program Final Edit

This is an updated version of my previous Java program that asks the user for a sentence and then separates the words and then converts the sentence into Pig Latin. My previous program was working, ...
4
votes
2answers
63 views

A Sub-string Extractor Implementation with Specific Keywords in Java

I am trying to implement a Java version sub-string extractor with "start keyword" and "end keyword" and the extracted result is from (but excluded) the given start keyword to (but ...
4
votes
1answer
39 views

Excel VBA Code for Imperial Length Measure Conversion and Formatting Yards Feet and Inches for English and Spanish

STR2INCHES is an Excel VBA Function that will convert string text for Imperial length measurements to a decimal number of Inches. It handles both English and Spanish words, abbreviations and symbols ...
2
votes
3answers
104 views

Convert string format python

I want to fix number of digits after '.' in digit represented by string. Is there better solution than mine? My code ...
4
votes
2answers
744 views

Return the first word with the greatest number of repeated letters

I'm learning JavaScript and have written a function that accepts a string and returns the first word with the greatest number of repeated letters. For example: Input:"Hello apple pie" - Output:"Hello"...
1
vote
1answer
95 views

A Tiny Text File Read/Write class Implementation in C#

I am trying to implement a tiny text file read / write class FileIO in order to make the operations of reading / writing pure text files easily. The usage is like: <...
0
votes
3answers
156 views

Convert first letter of every word to uppercase

I am learning swift and I came across this problem. Converting each start letter to capitalized form if it's lowercase. ...
2
votes
1answer
24 views

Input any time, output timezones that are currently that time

I made a program that will take in a time and a weekday, and return which parts of the world are at times closest to the one specified. Part of the program focuses on extracting a date and country out ...
2
votes
2answers
80 views

A Sub-string Extractor with Specific Keywords Parameter Implementation in C#

I am trying to implement a sub-string extractor with "start keyword" and "end keyword" and the extracted result is from (but excluded) the given start keyword to (but excluded) end ...
3
votes
2answers
69 views

I/O-TxtFile Line Distance Program

I am trying to write a lab/program that loops through a .txt input file. Reads an entire line of data as a string, then splits that string into an array delimited by a space. If there are 4 items in ...
2
votes
2answers
4k views

String compression implementation in C

I implemented basic string compression algorithm that uses the counts of repeated characters. For example: the string aabcccccaaa would become a2b1c5a3. What do you think about this, is there a better ...
3
votes
1answer
410 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
15
votes
7answers
5k views

Determining whether two scrambled strings are equivalent

I was able to complete the problem doing it in this manner, but I would assume there has to be an easier way. Sample input: abc, cba Output: Both strings of characters are equivalent. Or ...
5
votes
0answers
42 views

calculating upper bound on normalized weighted levenshtein distance

Current implementation I am using a normalized weighted Levenshtein distance for two utf32 strings with the following costs (insertion: 1, deletion: 1, replacement: 2). The normalization is performed ...
33
votes
10answers
85k views

Random string generation

I'm using this C# function to generate random coupons for a system. How can I improve it? ...
7
votes
2answers
5k views

Replacing each string of one or more blanks by a single blank

K&R 1.9 exercise: Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank. Is this correct and proper code? Could I have put ...
-4
votes
1answer
60 views

What does %s mean in a python strings? [closed]

I'm not sure what %s means in Python strings. I came across this line of code somewhere a while ago: ...
6
votes
1answer
315 views

K&R Exercise 1-21. Write a program `entab` that replaces strings of blanks with tabs

Intro I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it: learn (outdated) C and practice problem-solving at the same time. I believe that the author's ...
1
vote
1answer
52 views

Rust - insert into piecetable

I'm writing a piece table library in Rust with the structures: #[derive(Default)] struct Piece { additional: bool, offset: usize, length: usize, } and <...
4
votes
2answers
98 views

Converting a string into an array and returning the values spelled in reverse

I must create a function that accepts a string of names all separated by a comma. Example: "Jack,Matthew,John,Sam" And return the string of names in the ...

1
2 3 4 5
54