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
138 views

Word count graph

I created a program in python that reads a file and outputs a frequency graph of the words it contains. Any feedback or tips would be appreciated. ...
19
votes
2answers
5k views

String reversal in Python

This code will take as output any string (long, empty, with spaces...) and will return its reverse. Can I improve this algorithm so that it can be faster? Right now its complexity is \$O(n)\$. <...
6
votes
2answers
2k views

Find a best fuzzy match for a string

I am trying to find a best match for a name within a list of names. I came up with the below code, which works, but I feel that the creation of the intermediate ...
2
votes
0answers
64 views

Not a very interesting implementation of a simple substitution cipher in Python

I know this has been done before, but I needed to brush up my Python skills. Also, I intend to publicly share this code on a blog post sometime in the near future. This is also an attempt to improve ...
2
votes
1answer
100 views

Simple pattern matching between two string inputs using Java (Google interview challenge)

The interview question is: Write a function isMatch (without using java.util.Regex) that takes two strings as arguments: ...
3
votes
1answer
83 views

Decomposing a matrix as a sum of two bitstrings

I chanced upon this question and came up with the following algorithm, looking for criticisms and advice on how to improve my algorithm efficiency. You are given 3 arguments: A & B are ...
0
votes
2answers
94 views

Search files content fast in powershell

I need to search a large repository of files for a specific resource, and return it only if it is used or not. It is working as expected, but it is very time consuming. To search for 50 resource ...
7
votes
2answers
612 views

Version of C# StringBuilder to allow for strings larger than 2 billion characters

In C#, 64bit Windows, .NET 4.5 (or later), and enabling gcAllowVeryLargeObjects in the App.config file allows for objects larger than two gigabyte. That's cool, but ...
2
votes
1answer
121 views

(Codewars): Find the Unknown Digit

Kata: https://www.codewars.com/kata/find-the-unknown-digit/train/python To give credit where credit is due: This problem was taken from the ACMICPC-Northwest Regional Programming Contest. Thank ...
3
votes
2answers
276 views

Counting the number of ways to decode a string

I am working on problem where I need to decode a string: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... ...
5
votes
3answers
129 views

Confuse a text without making it unreadable

Scientists have found that a text can still be read even if only the first and last letter of a word are in their right place. The remaining characters within the word can be arranged randomly. ...
8
votes
1answer
159 views

A string_splitter using C++17

In this repo I've put together a header only string splitter, allowing for characters and string literals as delimiters. The (little) library is strictly C++17. I would like to ask for your comments....
2
votes
1answer
50 views

segstr - Get delimiter-separated segments from a string in a non-destructive method

I wrote my first useful function in C which can be used in a different variety of situations as an alternative to common code logic. segstr (originally named ...
1
vote
1answer
41 views

Random String Generation module in Python

The module is for facilitating random string generation. The example I use to explain it is the following: Instead of writing ...
3
votes
3answers
939 views

Remove excessive whitespace from string [closed]

Is that standards-compliant? ...
3
votes
1answer
118 views

C++ String class implementation

I wrote a simple String class implementation using unique_ptr and move semantics. Is my implementation good enough in terms of design and efficiency? Stringy.h <...
3
votes
1answer
45 views

Find a valid english phrase that is identical to what the user entered, save a missing consonant

The Task: The user enters a path to a dictionary file (one word per line) and a phrase as system arguments. My code must then find phrases containing only valid English words, generated by removing ...
3
votes
2answers
87 views

Splitting C string without modifying input

I wrote this after using strtok_r and needing something similar that can copy the input string and handle multiple characters in the delimiter. Its functionally ...
5
votes
3answers
287 views

My own getline function for reading strings from files

I am a newbie to C++ and I want to do some cool stuff with it. Here I have implemented my own getline function which reads from a file. so what do you think of this getline function? ...
0
votes
1answer
152 views

Reverse String in Java

I've been revamping on my coding puzzles practices. What is the complexity (both time and space) for this method? ...
5
votes
3answers
481 views

Functions to count vowels and consonants in strings

I am coming to a problem where I am writing a function that accepts a pointer to a C-string as its argument. The function should count the number of vowels appearing in the string and return that ...
3
votes
1answer
68 views

Concatenating an already existing filename to create a new file

I had answered this question from stackoverlow and the code below is code that I wrote to explain to the OP a possible way to achieve what I believe they were looking for. The general idea that I ...
8
votes
2answers
1k views

Concatenate words in such a way as to obtain the longest possible sub-string of the same letter

An array of N words is given. Each word consists of small letters ('a'- 'z'). Our goal is to concatenate the words in such a way as to obtain a single word with the longest possible sub-string ...
1
vote
1answer
132 views

Find all starting indices in a string which are anagrams of a word

The task: Given a word W and a string S, find all starting indices in S which are anagrams of W. For example, given that W is "ab", and S is "abxaba", return 0, 3, and 4. My solution: ...
1
vote
1answer
142 views

Find out whether string A can be shifted to get string B

The task: Given two strings A and B, return whether or not A can be shifted some number of times to get B. For example, if A is abcde and B is cdeab, return true. If A is abc and B is acb, ...
8
votes
4answers
2k views

Counting lowercase and uppercase letters in a string in Python

I am writing a program to count the number of uppercase and lowercase letters in a string. I came up with something that works, but as I am still a beginner I have a feeling writing the code this way ...
5
votes
3answers
95 views

if you gaze long enough into strtok, strtok will gaze back into you

The tokenise function below splits a given string at the indicated delimiters. As with strtok, it modifies the string by adding <...
3
votes
2answers
241 views

Find the longest sub string of a word after concatenation of given words array

An Array of N words is given. Each word consists of small letters ('a'-'z'). Our goal is to concatenate the words in such a way as to obtain a single word with longest possible substring composed of ...
6
votes
1answer
258 views

Find the longest common sequence of two strings in Rust

I've attempted to solve a small coding challenge I found online as a nice way to begin learning Rust. The largest challenge I feel going in with Rust is how working with strings is so fundamentally ...
1
vote
4answers
186 views

Read a palindrome of unknown length

I have a task to write the function: int read_palindrome(); // input comes from stdin which will read one line from standard input and returns 1 if the line is a ...
3
votes
3answers
109 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
1
vote
2answers
71 views

Count Substrings for a binary string

Problem is taken from leet code. Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings ...
0
votes
0answers
255 views

Time limit exceeded on HackerRank “Username Disparity”

Here is the hackerrank question: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of ...
1
vote
2answers
451 views

Python password generator

This is considered as my second python project, I made the password generator where user has to input length of password minimum 5. I made the code that it will guarantee at least one lowers case, ...
1
vote
0answers
77 views

KMP algorithm in scala

I implemented KMP pattern matching algorithm in Scala. My code works but it looks more imperative and a scala translation of C/C++ implementation. I am not able to figure out how to manage multiple ...
8
votes
4answers
3k views

Reversing a string - two approaches

Test Case: Input- "I'm hungry!" Output- "!yrgnuh m'I" Approach 1: In this approach, I used a empty string and bind it with the input string reversely. ...
1
vote
0answers
74 views

Brute force least adjacent swap anagram transform in Java

In this post, we are given two anagrams, and we wish to compute a shortest sequence of adjacent character swaps. For example, ...
4
votes
0answers
67 views

Improved Knuth-Morris-Pratt over a source of indeterminate length

Following the successful review of my previous implementation. Please review my new, generic implementation of the Knuth-Morris-Pratt algorithm. Its modified to search a source of indeterminate ...
4
votes
2answers
105 views

Knuth-Morris-Pratt over a source of indeterminate length

Please review my generic implementation of the Knuth-Morris-Pratt algorithm. Its modified to search a source of indeterminate length in a memory efficient fashion. ...
2
votes
1answer
72 views

Finding the longest word without these characters follow-up

Here I asked this question: My goal is to go through the list of all English words (separated by '\n' characters) and find the longest word which doesn't have ...
4
votes
2answers
800 views

C++ implementation of basic_string

This is a basic_string implementation that has SSO. It's not done, but the fundamental operations are all there (append, ...
2
votes
2answers
98 views

BigInteger check in C++ from a string

You might consider this question a follow-up of: BigInteger check in C from a string Although, this time, I used C++. I am on Linux Mint 19.1 with the compiler version: ...
4
votes
2answers
89 views

BigInteger check in C from a string

I have started to learn C. At the time of writing I don't know anything about the language. The following I wrote today in a few hours. Though I do have a lot of programming experience, I find C hard ...
0
votes
1answer
81 views

Find first repeating Char in String

Given a string, find the first repeating character in it. Examples: firstUnique("Vikrant")None ...
3
votes
3answers
6k views

String compression function in python code [closed]

I need to create a function called compress that compresses a string by replacing any repeated letters with a letter and number. Can someone suggest a better way to do this? ...
5
votes
1answer
3k views

Find longest common string subsequence

The task (also found at https://www.youtube.com/watch?v=10WnvBk9sZc): Write a function that takes two strings, s1 and s2, and returns the longest common subsequence of s1 and s2. "ABAZDC", "...
2
votes
4answers
1k views

A simple function that removes empty or tags containing just '&nbsp;'

I've written a function that should get rid of empty p, span, etc tags and those with just ' ' and am looking for ways to improve it. My original solution was very 'wet', but I've managed to come ...
3
votes
2answers
109 views

Determine whether a word appears in a sentence

Given an array of words representing a sentence and a word to search for, the method must determine whether the word appears in the sentence. Specifications Case insensitive. The arguments are never ...
3
votes
1answer
91 views

Printing (number, uncertainty) pair in a formal way

I am trying to do an auxilliary function to print pairs of value-uncertainty in a formal way, given their name, value and uncertainty. The "technical" agreement is that "uncertainty rules", meaning ...
1
vote
2answers
113 views

Simple ES6 Truncate method for character, word, and sentence limits

Simple truncating method for characters, words, and sentences for a personal utility library I've been working on. Improvements & criticism welcomed! Especially around default param usage, as I'...