Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
0answers
34 views

Comparing 100,000 string pairs, quickly

I recently compared various comparison operators in ColdFusion 2016 ...
3
votes
1answer
125 views

Convert boolean list to list of base10 integers

Context: I'm coding up a simple genetic optimization algorithm from first principles, and have decided to use boolean/binary strings as genes so that I can flip bits on or off as a form of mutation. ...
1
vote
3answers
56 views

Printing a table of letter frequencies using Python

What is the recommended (standard, cleaner, more elegant, etc.) method in Python to get a string with all the alphabet letters? Here's three versions of code to generate a dictionary with keys as ...
-2
votes
0answers
23 views

search for 2 words in string using python [closed]

key='side by side' wordstring=['How to use side by side in a sentence','the word side remains'] I want to check if the key is fully present in ...
9
votes
4answers
1k views

Program that finds the longest word not containing one of the disallowed characters

Problem definition Find the longest word that doesn't contain any of the following characters: gkmqvwxz Input comes from a file named ...
-2
votes
1answer
42 views

Remove key-value pairs from string when only key is given

I have a need to parse strings that contain pairs of key : value, and remove a specific pair, when I'm only given the key. Example: Given the string ...
0
votes
1answer
36 views

CodingBat warm up: conditionally prepending “not” to a string

I solved this CodingBat problem: Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. Note: ...
0
votes
1answer
51 views

Formatting list of queries in python

I have a file of SQL (actually HiveQL) queries terminated by semicolon (;). I need to obtain ...
4
votes
1answer
28 views

Find labels in string in Haskell

I wrote code that parses a table header string in order to obtain two string tags, one for variable name (like GDP) and another for unit of measurement (like ...
1
vote
2answers
78 views

Converting a String to USD

I'm working on a clientside iOS app for my school that involves students purchasing things, and I wrote a String extension for formatting a ...
2
votes
2answers
52 views

Method that receives a hexadecimal string and returns a formatted matrix of those values

This method is part of a larger project and comes after encoding ascii characters into hexadecimal values, so it assumes the parameter is always a valid hex string. ...
4
votes
2answers
66 views

C++ string tokenizing without streams, with certain conditions

My concern is mainly the correctness of the algorithm for tokenizing purposes. The code compiles as it is called as a member function in my program. The code does pass my small amount of unit tests ...
7
votes
3answers
518 views

Count number of gemstones in a set of minerals

This is the "Gemstones" problem on Hackerrank. John has collected various rocks. Each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range ...
11
votes
2answers
3k views

Make a beautiful binary string

This is the "Beautiful Binary String" problem at HackerRank: Alice has a binary string. She thinks a binary string is beautiful if and only if it doesn't contain the substring 010. In one step,...
1
vote
2answers
54 views

Check if a string is a valid english word, and convert to a valid english word

This is an interview question. For the purpose of the question, a valid English word is a string that begins with an uppercase English letter, and the rest of the string contains only lowercase ...
1
vote
3answers
86 views

Checking if a string is funny or not

The idea is this: To determine whether a string is funny, create a copy of the string in reverse e.g. . Iterating through each string, compare the absolute difference in the ascii values of the ...
4
votes
2answers
111 views

Templated string formatting

This function formats a string by replacing every occurrence of '{n}' with the corresponding argument that was passed to the function where n is an index that ...
3
votes
2answers
80 views

Swapping pairs of characters in a String

Question: Write a program to swap pairs of characters of a String. In case of odd number of characters last character should remain unchanged. Examples: Input: HI Output: IH ...
10
votes
2answers
114 views

Prettifier isn't pretty

Some context I'm implementing a self-closing pairs auto-completion feature in Rubberduck. One of the challenges is that the VBIDE API doesn't allow editing a line of code by "injecting" characters: ...
2
votes
1answer
78 views

Safe string formatting in Python

I am a fan of f"{strings}" in Python, However some situations could possibly be dangerous when doing f strings from user input, leaking API keys or even code ...
3
votes
3answers
1k views

Find longest Palindrome substring

I am preparing for technical interview and I found this question on geeksforgeeks, but I did not understand their solution. So, I have written my own solution. I want to optimize this code. ...
0
votes
1answer
64 views

Parse JSON strings as tables using Python

Needed a simple CSV file that had headers and no nesting of data to consume in Tableau. The JSON file I was consuming had nested dictionaries and lists (which sometimes had in themselves nested lists/...
4
votes
2answers
105 views

Longest word in dictionary that is a subsequence of a given string

I am trying out the following former Google interview question. The Challenge Given a string S and a set of words D, find the longest word in D that is a subsequence of S. Word W is a ...
5
votes
2answers
43 views

Rust Echo Command Implementation

I'm just starting out in Rust and I find the concept of ownership confusing so I wrote an implementation of the echo command. I would like to know if I could have ...
3
votes
3answers
141 views

Morgan and a String HackerRank challenge

I am solving a HackerRank problem called 'Morgan and a String'. Given two strings, each consisting of up to 105 uppercase characters, the task is to form the lexicographically smallest string from ...
0
votes
1answer
40 views

Prevent multiple ifelse statements in php [closed]

I'm trying to figure out a way to make my code more readable and maintainable. While rewriting some ugly spaghetti code, I stumbled across this: ...
2
votes
1answer
52 views

Split a string based on a delimiter in C

Basically, this code splits a string into substrings based on a token. The printf call is just a placeholder for something useful for each substring and can be ...
1
vote
2answers
34 views

Output string length and classical Fibonacci sequence in a web page

I wrote a JavaScript and XHTML webpage. I think the format of the output is not better or the validation process is not as it is supposed to be. How can I improve the code? How can I make it more ...
0
votes
1answer
33 views

Formatting fractions found in a given string to html fraction

I'm working on a site running woocommerce and wp where the user will add/has added a dimension attribute. The dimension string will take the following format originally: Ht: 30 1⁄2" W: 22 1⁄2" D: ...
3
votes
0answers
63 views

Count number of substrings which contains particular strings

I need to count the number of substrings of s which contains both the strings a and b. This ...
3
votes
2answers
79 views

Converting an input string to a list of sub lists with numbers

I am learning Python 3. One thing I am doing to get some repetition is going through checkio. It is a website with coding exercises. One of the exercises gives an input string as follows: ...
2
votes
2answers
46 views

Find a palindromic string in C

This program tests whether a string is a palindrome or not. Can there be any improvements or shortcuts that can be used in the program. You can give any type of string as input. The program finds does ...
6
votes
2answers
193 views

Random quote rotator

On my website, I created like this banner that rotates quotes from an array I made. ...
3
votes
1answer
60 views

Convert string of hex into vector of bytes

I want to write a function that gets a string of hex numbers (two hex numbers represent a u8 value) then returns a vector of u8 ...
0
votes
1answer
18 views

Embolden parts of auto-complete suggestions that don't match the query

I made a function to embolden text that doesn't match a string, but it appears to be very performance-heavy. I am certain that there are much better ways to do this, but with what I tried, I ran into ...
2
votes
0answers
65 views

Madlib CLI program, replaces string in text file

Mad Libs program that reads in text files and lets the user add their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB appears in the text file. ...
4
votes
1answer
96 views

Multiple client TCP stream reader

My server code is currently reading String data over a TCP connection form 2 different client computers. To do this I am duplicating the ...
3
votes
2answers
39 views

Utility functions for processing tweets or texts

I have 4 functions that process texts or tweepy.models.Status object (this object stores text information, author information, retweets & likes information of a ...
6
votes
2answers
565 views

Looping through a string finding nested brackets

So I've been trying to check through a string, looping for, [ (start) and ] (end). In this, I also have to check for nested ...
0
votes
1answer
59 views

Shuffle a string in a repeatable way

The following function is designed to accept a string of characters and an integer. The function returns a string that's a reordered version of the original string. The reordering process is ...
5
votes
3answers
296 views

Function for creating unique strings for urls

I wrote this function in order to create unique url's for my site. Using these urls, visitors could demo site functionality without having to create a login. The function was intended to return a ...
4
votes
3answers
56 views

Replace $number with $number+1 in std::string

I want to detect $number substring in std::string and then replace it with $number + 1. For ...
2
votes
1answer
39 views

Search and Replace (FreeCodeCamp intermediate algorithm scripting)

I completed the challenge and passed the tests: Perform a search and replace on the sentence using the arguments provided and return the new sentence. First argument is the sentence to perform ...
1
vote
1answer
42 views

Bool function in PHP to check if you run the script inside docker

I had to do a CLI script that does something, I also had to add a validation that checks if it runs inside the Docker. After a research I found a solution that people check some processes via ...
4
votes
5answers
166 views

Use filename to determine file type

This is legacy, so I'm not really looking for improvements on architectural approach. Here's what the method does: Extracts filename from a string containing full file path (passed in as parameter) ...
10
votes
1answer
851 views

string length in x64 assembly (fasm)

Please critique this very, very basic routine which returns the length of a given char buffer or "string." ...
0
votes
0answers
72 views

Minimum Window Substring in JavaScript

I find this Substring Leetcode challenge online. Given a string S and a string T, find the minimum window in ...
3
votes
2answers
120 views

Attempt at checking whether two words are permutations

This is my first algorithm in C++ ever to check if two strings are permutations of each other. Please provide guidance on correctness of algorithm + ways to improve + thoughts on my use of the ...
5
votes
4answers
142 views

In-place reverse of C-style string

This is a question from the book "Cracking the Coding Interview". Write code to reverse a C-Style String (C-String means that “abcd” is represented as five characters, including the null ...
6
votes
2answers
1k views

Generating a unique key

I am coming from a Ruby background and I am learning Python. This is a method I've created to generate a URL safe unique key: ...