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
15
votes
2answers
631 views

Convert camelCase and PascalCase to Title Case

I'm trying to take camelCase and PascalCase strings into a function and spit them out as Title Case. This function also needs to be able to handle odd PascalCase strings with capitalized abbreviations ...
1
vote
0answers
37 views

string.To2DCharArray extension method implementation

I would like to ask a code review for the class below. I am asking this because VS showed a quite low Maintainability Index of 54 and I am wondering if it is good code. I know I could have extracted ...
18
votes
6answers
3k views

Comma Code - Ch. 4 Automate the Boring Stuff

I am new to programming and currently learning Python using "Automate the Boring" by Al Sweigart. I've just completed the "Comma Code" task in Chapter 4 and would like some feedback on my solution. ...
4
votes
0answers
171 views

Rabin-Karp algorithm implementation

This code uses the Rabin-Karp algorithm to compare two text files. It takes a few minutes when both files contain around 1000 words. How can I improve? ...
3
votes
1answer
310 views

Palindromic partitions solution

Task Find the smallest number of cuts required to break a string into a set of valid palindromes. For example: ababbbabbababa becomes a|babbbab|b|ababa (cuts = 3) partytrapb becomes partytrap|b (...
3
votes
4answers
125 views

Finding the Longest Word in a String

Challenge: Return the length of the longest word in the provided sentence. I've made a solution that works but it is kinda bad since the time complexity is \$O(n \log n)\$ and it involves mutation....
2
votes
2answers
66 views

Generating a list (or a string) with random elements

During implementation and testing of different small hobby projects I often reach the point where I need (at least I like it more) some random data beyond the usual foo-bar strings or lists. Random ...
2
votes
2answers
1k views

Python program to get the first word

Given a string the task it to find its first word with some rules: The string can have points and commas A word can start with a letter, a point or space One word can contain one apostrophe and it ...
1
vote
2answers
974 views

Python program to get the longest substring of the same character

Given a word the program outputs the length of the longest substring with the same letters. For example: long_repeat('sdsffffse') == 4 long_repeat('ddvvrwwwrggg') == 3 long_repeat('abababaab') == 2 ...
3
votes
2answers
105 views

Python program to translate sentences from “bird language”

Given a sentence in 'bird language', where there are two rules: After each consonant there is a random vowel added. For example if the consonant is "l" it will end as "la" or "le"... After each vowel ...
1
vote
2answers
55 views

Function to count words in Python

I am new to developing in Python and would like to see comments about my word count solution. Please indicate my mistakes or best solutions. ...
4
votes
1answer
63 views

Count the number of words and lines that have multiple vowels

I am working on this coding problem: Count the number of words & lines that have more than X vowels for every Y words in every Z line. Basically the input string has multiple lines and I need ...
4
votes
1answer
46 views

Python program to know who wins a tic-tac-toe game

Given an input where we have two players: "X" and "O", and empty cells marked with a "." like: check_winner([ "X.O", "XX.", "XOO"]) the program outputs if there are three "X" ...
2
votes
1answer
88 views

Removing first or last character of a string with unit-testing

I am trying to remove a duplicate letter of first or last letter, with an exception of containing 'a' as first letter and 'l' and 'e' as last letter. However, this code does not look efficient to me ...
6
votes
1answer
103 views

Find words with this prefix

This function (find_prefix) is supposed to find words starting with a given prefix in a container. The container is sorted. This function is a fairly performance-...
15
votes
8answers
6k views

Python program to take in two strings and print the larger string

I have written a Python program to take in two strings and print the larger of the two strings. Here is my code - ...
3
votes
1answer
160 views

Random String Chooser

I was tasked with creating the class RandomStringChooser that prints the strings in the passed array in a random order, based on the ...
21
votes
4answers
5k views

Count all vowels in string

For a homework assignemnt, I was asked to complete this CodeStepByStep problem. It's coded correctly and gave me a right answer. I'm just wondering if there's an easier way to solve this problem ...
2
votes
0answers
70 views

Faster way to replace strings in pandas series using dictionary in Python

I'm working with a dictionary with 11830 keys/values, that have to loop over 13905 strings, that can have up to 50 words each. My series looks like this: ...
5
votes
1answer
115 views

Identify fraudulent bank transactions

Task: Return true if a transaction is allowed and return false if transaction is prohibited. Details: 1. String is represented as an "array" that can contain up to three elements. We need to ...
4
votes
1answer
88 views

Preperiodic, periodic or aperiodic binary string

This is extension of the rep-string task from Rosette code. I do not only want to check if the input string is the shortest periodic string (rep-string) or not, but also check if it is preperiodic. ...
1
vote
2answers
61 views

Optimize printing massive strings to System.out with respect to time

I need to cut the time it takes to print a large string by ~50%. I went from using s1 + s2 to using StringBuilder, and instead ...
5
votes
2answers
562 views

Search string in file, replace it, and write back to file

I have this simple function that just reads a file, replaces all occurances of a string, and write it back to the file: ...
5
votes
2answers
959 views

Find hamming distance between two Strings of equal length in Java

I have a private class that I want to be able to find the shortest Hamming Distance between two Strings of equal length in Java. The private class holds a char[] ...
5
votes
4answers
320 views

Determine if a string only contains repetitions of a substring

This is my first Python program in years, it's just a simple string manipulation program. Given a string, determine if it contains repetitions of any substring. For example, ...
3
votes
1answer
56 views

Extracting small word parts (quadgrams) from text using R

I would like to extracts small word parts (quadgrams) from text. Example: hello world results in: ...
12
votes
4answers
839 views

Cropping a message using array splits

I am trying to write a simple function to crop a given message to a specific length but at the same time not to cut the words in between and no trailing spaces in the end. Example: Input String: ...
8
votes
3answers
422 views

Static utility class for string manipulation in C++

My programming foundations were formed in Java, but I've decided to only use C++ from now on for my projects as a personal learning experience. Static utility classes are common in Java; but I don't ...
6
votes
2answers
402 views

Generating 10-character passwords, with 3-6 digits and 3-6 uppercase letters, in C++

In response to a question on Information Security on brute-forcing passwords, I wrote code that helped solve the problem: Generate a password list of 10 character passwords containing only a ...
2
votes
1answer
36 views

Determine if an array of arrays of characters can be concatenated in order, into a substring of haystack

Algorithm: Determine if an array of arrays of characters can be concatenated in order, into a substring of haystack. Example: ...
10
votes
2answers
583 views

Extracting the parent, leaf, and extension from a valid path

Powershell has the Split-Path cmdlet which allows you to extract the Parent and Leaf of a file. In PS version 6, you can extract the extension, with the ...
2
votes
3answers
171 views

Armstrong number generator

This is my code to generate all possible Armstrong numbers between the two given numbers. The logic uses string instead of integer to separate the digits to optimize the code. ...
-2
votes
2answers
175 views

ArmstrongNumber checker

This is my code written to check whether a given number is armstrong or not . but the logic differs from the conventional logic of using integer and separating its digits and calculating , instead i ...
1
vote
2answers
43 views

Trimming strings in non-contiguous spreadsheet ranges

This code is tested and works, but I am needing some guidance on simplifying these loops with non-contiguous ranges. I was thinking an array might be better, but I ...
3
votes
1answer
166 views

Splitting a long string based on its graphical presentation

I got a long string, let's call it Story. I fetch this story from a database so I don't know how long it is. I want to display this story in a view, but what if ...
1
vote
1answer
76 views

Calculating the seconds between 2 numbers in a specific place in a string

We have a ...
3
votes
1answer
146 views

Python snippet for finding word in string

I wrote a simple function that finds a word in a string without use of the re module. My function looks like this: ...
7
votes
4answers
3k views

Reverse the word in a string with the same order in javascript

I want reverse the string with the same order. We should not use the Array functions like split(), .reverse() and some other array functions also except ...
8
votes
1answer
70 views

Checking whether a string fragment could be part of a longer UTF-8 string

Although UTF-8 validation is a common task, I'm trying to solve a slightly different task; given a string of bytes, work out whether it could potentially be a fragment of a valid UTF-8 string. That's ...
6
votes
1answer
97 views

Rendering tree of nodes as string

I'm creating a debug-view for my expression-trees. They record each operation automatically in a tree that I am transforming into string so that I can see the exact ...
1
vote
0answers
31 views

Average histogram combining multiple files and vector of vectors (in c++)

I run a program of simulation N times (I use each time a different random numbers to initialize it). The results of the program are stored in 2N directories: every run produces two approximations. The ...
1
vote
1answer
54 views

Bubble sort in C (for strings)

What do you think of this bubble sorting function in C, for a string array? I would like to improve the readability, performance, and any good practices. ...
0
votes
1answer
35 views

Building complex sentences based on a data structure

I really do not like how bad this looks. It is not readable and I am not sure if I need the stacked map's. There are a lot of iterations going on here (map, join, replace) and performance is really ...
2
votes
1answer
115 views

Converting words/numbers to Discord “letter/number emojis”

I am a beginner to Python (and programming overall) and I decided that it would be funny if I wrote a program that could convert Letters/Numbers to these "Letter Emojis" in Discord. It works but I am ...
2
votes
1answer
139 views

Game to shuffle and guess a word

I'm new to C++ and while learning, I wrote a simple program that asks for a word, shuffle sthe characters and then asks another person to find the original word, given the shuffled letters. I would ...
1
vote
1answer
48 views

Efficient way to add a colon before and after every word in strings inside a Series

I was working with twitter data, and extracted every emoji from the data. But, when I passed that data through CountVectorizer, colons where substracted from the ...
0
votes
1answer
72 views

Combinational string search using Java

I wrote a program that receives 2 strings (Input and Search) in the Search string. The sign '+' indicates that if the substring before the '+' exists in the Input string. (The search string cannot ...
4
votes
1answer
41 views

Count words in a list of titles, with some cleanup

I have a list of article titles, where I wish to count the number of occurrences for each word (and remove some words and characters). The input is in a .csv file where the titles are in column '...
4
votes
2answers
59 views

String joining function in C

I wrote a function that joins a collection of Strings with a delimiter. It's based on Java's version of the function. I'm assuming C has some similar built-in. Example: ...
3
votes
4answers
116 views

Linux wc command in C

I'm working on my implementaion of the linux wc command. I finally have something that is working properly (with no options yet) but i think it needs a lot of "cleaning". I mean, i highly disrespect ...

1
3 4
5
6 7
52