Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
7
votes
3answers
183 views

String routines

These are a few string routines (just the mem* ones). I've tried to optimize them the best I can without having them be too big, but I'm unsure if I've done a good ...
3
votes
2answers
85 views

Reverse chars of each word in a string

An algorithm to reverse characters of each word in a sentence. What would be your concerns regarding the following solution? Example input: "I love New York" output: "I evol weN kroY" ...
0
votes
1answer
49 views

String manipulation in Python

I have this very ugly piece of code which runs ethtool and then parses the output (Lilex is just a static class encapsulating subprocess and is not relevant to the ...
3
votes
2answers
50 views

JavaScript number obfuscater

I got inspired to do this after seeing this repo containing a bunch of weird syntactical quirks in JS, namely this example called "It's a fail!". The example was essentially the following: You ...
1
vote
4answers
148 views

“String” contains function in C

This function checks whether or not a substring needle exists in another string haystack and returns the position if it does or ...
3
votes
2answers
903 views

Can this code, to convert string to integer, be made more compact?

Problem: String to integer(leetcode) Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as ...
2
votes
0answers
32 views

Command String Parser

I'm working on a library that, in essence, splits a string at whitespace, with extra rules: Consecutive whitespace is collapsed, and trimmed at the start and end. Whitespace wrapped in quotes is not ...
4
votes
1answer
87 views

Create HTML structure dynamically

We had a long HTML string with information about the makers of our software. However, for i18n this was unwieldy. So I started to refactor, so only each person's description is translateable, not all ...
2
votes
0answers
70 views

Rosalind - Finding a Shared Motif

Here is my attempt to implement the Ukkonen algorithm for the Finding a Shared Motif problem on rosalind.info. The code works, it produces a correct answer. It does so in 11 seconds. I am hoping to ...
6
votes
1answer
40 views

Search for strings in a list that have > 90% similarity

Explanation: I am working on String comparison in which I want to cross-compare the list of the same input string. For the same string, I am continuing the loop but if a single string will have ...
3
votes
1answer
231 views

Lightweight read-only string implementation (C++)

In C++, currently we have few possibilities to work with strings: by using plain old C-strings - unfortunately, we have penalty for getting length of string each time, and we should manually control ...
3
votes
1answer
46 views

Determine fragment identifier from HTML page in Swift

For an iOS app which helps me rolling back vandalism on Stack Exchange, I have a piece of Swift code which downloads a revision page (example) and tries to find the 'spacer' fragment just above a ...
5
votes
2answers
656 views

Reducing the time for rolling hash

I tried this problem below and solved it in O(test_cases * string_length * pattern_length) complexity involving three nested loops.I want to know how can i further decrease time. I figured as much: 1:...
1
vote
1answer
42 views

Short function to remove unnecessary whitespace

I have a function consisting of one line of code: def trimString(string): """ Remove unnecessary whitespace. """ return re.sub('\s+', ' ', string).strip() ...
3
votes
1answer
133 views

String.IndexOfAny(string, string[]) (lowest position for group of needles in haystack)

This is a follow-up to this question with bug fixes, question and code improvements from @dfhwze, @PieterWitvoet, @HenrikHansen, @t3chb0t. I am still hoping for an improved approach or algorithm ...
1
vote
2answers
175 views

Best C# implementation of IndexOfAny(string, params string[])

Follow-Up question .Net provides String.IndexOfAny(string, char[]) but not String.IndexOfAny(string, string[]). The existing ...
2
votes
1answer
40 views

CodingBat: without_end

Link To Question Given a string, return a version without the first and last char, so "Hello" yields "ell". The string length will be at least 2. without_end('Hello') → 'ell' ...
4
votes
1answer
51 views

Porting stemming algorithm from Java to Python

I have ported Stempel stemmer in Java (Apache Lucene) to Python. I come from Java world, so I'm afraid my translation might not be "pythonic" enough. I would like to hear your feedback on quite ...
4
votes
2answers
86 views

Letter case permutation

The question can be found here https://leetcode.com/problems/letter-case-permutation Given a string S, we can transform every letter individually to be lowercase or uppercase to create another ...
1
vote
3answers
34 views

`set_includes` (string subsequence-containment) in Python 2

I've implemented C++'s std::includes algorithm in Python, so that I can use it to efficiently implement a Scrabble "can I make this word" function: ...
4
votes
1answer
93 views

Random password generator (Java)

I wrote this program recently to generate random passwords for myself. It works well but it's been a long time since I wrote any java and am just looking on ways to clean up the code. I'm also not ...
5
votes
4answers
253 views

Reverse the word order in string, without reversing the words

I was tasked with using C++ to turn this "Hello Jarryd, do you like socks?" into: "socks? like you do Jarryd, Hello"; Edit: The condition was to reverse this in place. Here's what I came up with, ...
2
votes
1answer
66 views

Remediation for security vulnerability due to storing sensitive information in strings

Security assessment of our codebase reported the following vulnerability - Vulnerability Description The method x() in xyz.java stores sensitive data in a String object, making it ...
6
votes
4answers
618 views

Maximum character insertion

I would like to know any suggestions about to improve my code and/or get a better approach for this problem solution and your rating of my approach to the problem.(besides removing the ...
3
votes
1answer
64 views

Random password generator with choice of three strengths

My code works fine but I definitely have unecessary repeat code. I'd like to use functions so I don't have repeat code. I would appreciate any advise on how to make my password generator code more ...
2
votes
1answer
60 views

Find the number of all specific substrings in a string

I would like to ask a code review regarding a concrete exercise. Let's suppose I have to get the number of all specific substrings in a string. We call something specific if any of these conditions ...
1
vote
5answers
86 views

PHP function to obtain model_name from Namespace\To\ModelName

Would there be a more clear/efficient way to write ...
6
votes
2answers
124 views

String manipulation with std::adjacent_find

For the given strings (not containing numbers), print their shortened versions, where each adjacent sequence of the same characters longer than 2, change to an expression consisting of a sign and ...
4
votes
2answers
49 views

String validation based on multiple criteria

I had me a code challenge and I was thinking: is there a way to make this more efficient and short? The challenge requires me to scan a string and ... In the first line, print ...
4
votes
3answers
2k views

Palindrome test

This is some code that determines if a string of characters is a palindrome or not. My professor says that there is a performance issue with the program, but I can't quite put my finger on it. Can ...
5
votes
1answer
199 views

WPF Palindrome Checker Application

I made a WPF Application, called Palindrome Checker, which checks if what you input is a palindrome. Any and all tips on how to make this code better in all capacities are wanted and appreciated. <...
2
votes
2answers
91 views

Check whether a string has all unique characters (time efficiency)

I don't find this algorithm in Go language here, so I just want to check that it is really most efficient algorithm in Go: ...
1
vote
1answer
296 views

String Rotation

I have solved a previous year question of 2018 codevita (link) in Python. Problem Description: Rotate a given String in the specified direction by specified magnitude. After each rotation make a ...
1
vote
3answers
79 views

LeetCode:implement strstr C#

https://leetcode.com/problems/implement-strstr/ I implemented Rabin-Karp algorithm https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm please review for performance, also if you were in an ...
16
votes
6answers
2k views

Avoiding repetition when using the “snprintf idiom” to write text

I'm writing a function to stringify a nested struct. I'm using snprintf to pre-calculate how much space I'll need to allocate. The problem is, it's extremely ...
8
votes
2answers
285 views

Sentence editor

I wrote a simple sentence editor which capitalises first word, deletes redundant spaces and adds a dot in the end unless another sign of punctuation is already present. Please help me to improve my ...
3
votes
3answers
123 views

String Zigzag Conversion

Overview The string 0123456789 is written in a zigzag pattern (following the path going all the way down, then diagonally moving towards the top right) using a ...
3
votes
1answer
81 views

Left or right padding a string with the specified character

Can I improve performance of below method? Is there anything I need to optimize or any redundancy I need to remove to make it more efficient? It's a simple method used to pad strings by left or right. ...
2
votes
1answer
47 views

Culling strings from a list that are substrings of other list elements

I'm bothered by my answer to this SO question. I'm pretty sure it's more efficient than the sort-and-cull implementations, but I'm having trouble expressing that in a way that I trust. Also, it's ...
6
votes
1answer
818 views

Avoid using C Strings on C++ code to trim leading whitespace

I'm learning C++ and wrote a function to remove all the spaces and tabs at the beginning of the input string. It removes them until it find a character different of space and tabs. In the first ...
2
votes
1answer
39 views

Length of the longest common sub sequence bottom up

Could I get some feedback on this code? I included a test case as well. This code computes the longest common sub sequence given paired data, it was not part of any challenge I just did it to learn ...
3
votes
1answer
56 views

State machine translates text into executable python code [v2]

A few days ago I started writing my own compiler-like program which has the goal to compile plain text into executable python code. After I let my first version review here, I made huge changes to the ...
1
vote
0answers
542 views

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

The task is taken from LeetCode - From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). Given two strings source and target,...
5
votes
1answer
204 views

A recursive Boggle solver

`Boggle is a word game in which letters are randomly placed in a 4x4 grid e.g: A D Q P N L E M O S R T V K J H Words can be started from any letter and are ...
0
votes
0answers
29 views

Create a template literal tag to remove whitespace from a string

I'm just getting into functional programming (as in, just started reading the book) and as practice I'm trying to refactor a past answer I wrote to fit in line with the functional style. The ...
3
votes
1answer
59 views

CareerCup (Bloomberg): Check if string is valid based on brackets

The goal of this problem is to determine if a string with brackets is valid. Below is a summary of the question from careercup. Check if string s is valid based on brackets ...
18
votes
6answers
4k views

Explicit song lyrics checker

To stay in practice with my Python I've decided to write an explicit song checker. It checks each word in the song against an array of 14 explicit words contained in the text file. I've decided not to ...
2
votes
1answer
79 views

Coding Challenge: Return The Smaller String

A coding challenge in which we are to write a function that compares two strings and returns the one that is smaller. The comparison is both lexicographical and numerical, depending on the content of ...
4
votes
2answers
73 views

RegEx version control

this is my first time on this stack exchange :) I created a little script to check for the latest version of specified API version available, but I am wondering if I am using the best way possible ...
5
votes
1answer
106 views

Find the longest word in a string

I have written code in the language Go. I wonder if anyone can do it in a very simple and effective way, because every language has its own way to solve this problem. My experience is in JavaScript. ...