Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
3answers
83 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 ...
2
votes
1answer
41 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 ...
-3
votes
0answers
16 views

Checking whether a particular prase exists in a string of message [on hold]

I have two files, called MESSAGE and PHRASE.... Message : ...
8
votes
2answers
779 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
61 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
1k 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 ...
4
votes
3answers
81 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
81 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 ...
5
votes
1answer
97 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
114 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 ...
2
votes
3answers
74 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 ...
0
votes
2answers
38 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
65 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
61 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
23 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
2k 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. ...
0
votes
0answers
39 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
38 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
92 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
65 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
749 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, ...
0
votes
1answer
36 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
80 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
61 views

Find first repeating Char in String

Given a string, find the first repeating character in it. Examples: firstUnique("Vikrant")None ...
3
votes
1answer
143 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
79 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 ...
2
votes
1answer
64 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
51 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
70 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'...
3
votes
1answer
112 views

C++ string class implementation, providing support for various C++11 features

This is my implementation of a string class similar to std::string and supports the following: range-for loops iterators basic ...
4
votes
3answers
103 views

strlen and strcmp implementation in x86 FASM assembly

I wrote my own implementation of strlen and strcmp from C in x86 FASM and I would like to know is there anything that should be changed or improved. strlen needs string in eax and is returning length ...
2
votes
3answers
319 views

C Primer Plus - Chapter 4 - Task 6 (string output) [closed]

Task Write a Program that requests the user's first name and then the user's last name. Have it print the entered names on one line and the number of letters in each name on the following line. Align ...
2
votes
1answer
77 views

String reversing x times

Inspired by CodeWars We have a string s Let's say you start with this: "String" The first thing you do is reverse it: "gnirtS" Then you will take ...
2
votes
1answer
132 views

LeetCode #28 - Boyer Moore string matching algorithm

The following code implements the Boyer Moore string matching algorithm. The algorithm is used to find a sub-string (called the pattern) in a string (called the text) and return the index of the ...
1
vote
1answer
66 views

Scheme: FSM substring search

I have been working on a function that return a FSM that searches a specific word based on the argument of the constructor. The idea was to use those routines as means to learn about regular ...
1
vote
2answers
53 views

Form a string consisting of the common letters that appear in two input strings

The idea is to write a function that takes two strings and returns a new string that repeats in the previous two: examples: ...
1
vote
0answers
25 views

change a string and apply changes to other similar strings

I'm trying to get the changes that were made in a string and apply them to similar strings. string are similar if they are equal from 0 to index of change. let's say I have this strings: ...
0
votes
1answer
36 views

Print words in decreasing order of frequency in Scala

Given a string print its words in decreasing order of frequency. Example: i/p - "aa bbb ccc aa ddd aa ccc" o/p - aa,ccc,ddd,bbb Scala: ...
6
votes
2answers
181 views

Extract specific positions from a char array

I have two arrays: char input[] = "ughIuytLikeretC"; and ...
3
votes
1answer
24 views

String contains non-overlapping letter pairs

I was trying my hand at learning Elixir via ancient adventofcode puzzles and was trying to write a function to satisfy this requirement: It contains a pair of any two letters that appears at least ...
7
votes
2answers
2k views

Generating strings dynamically in Python

I'm generating a URL (in string) that depends on 3 optional parameters, file, user and active...
3
votes
1answer
49 views

Reduce the length of words in a sentence

This function's goal is to reduce the length of a sentence to exactly max_length characters by cutting each word in the sentence ...
2
votes
1answer
82 views

Find out whether a given text contains any of the prohibited words

We have been given a list of strings which are blacklisted. The goal is to identify if a given text contains any of these blacklisted strings. The restriction here is that the blacklisted string needs ...
6
votes
3answers
188 views

Function to return subword of a camelcase string

Given a camelcase string and an index, return the subword of the string that includes that index, e.g.: ...
2
votes
1answer
64 views

Transforming full names to surname and initial

I have a large data frame that I want to merge with another dataset. In order to do so I need to get the names of individuals into a certain format. The function below converts the name in 'column' to ...
2
votes
0answers
30 views

vb.net Create textfile from template

What is the best approach for creating textfiles from/with a template ? Currently I just read the template from a textfile and Replace all values needed, but I don't think that this is the most solid ...
3
votes
1answer
106 views

Counting vowels and consonants in a string

The output should display as follows... ...
2
votes
2answers
44 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
1answer
66 views

Program finds the first almost matching string in a list - Advent Of Code 2018 Day 2 Part 2

Advent of Code 2018, day 2, part 2: The [two IDs you are looking for] differ by exactly one character at the same position in both strings. For example, given the following IDs: ...
4
votes
2answers
73 views

Count characters in a string

This code is supposed to count each character in a given string and account for error handling and type casting as well, and it should do it in the most efficient manner possible, with O(n) being an ...