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
votes
0answers
20 views

Code to find character count in strings [on hold]

I need to create a code that will take a string as input and create a dictionary containg character count and list of characters with that character count. For eg. If input string is: 'aabbcdeee'...
9
votes
3answers
357 views

Comma Code - Automate the Boring Stuff with Python

Below is my code for the Comma Code problem from Chapter 4 of Automate the Boring Stuff with Python. Is there anything I can do to make it cleaner? Comma Code Say you have a list value like ...
4
votes
2answers
55 views

A C# struct representing a string that can be neither null nor white space

I've written a C# struct in order to encapsulate the idea of a string being neither null nor ...
3
votes
1answer
46 views

LeetCode Reverse Words in a String without using any java library

The following problem is from LeetCode: Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. ...
7
votes
1answer
50 views

Replacing spaces with tabs. Exercise 1-21 in “The C Programming Language”

I'm looking for feedback on the code I came up with for exercise 1-21 in "The C Programming Language" by K&R. Write a program entab that replaces strings of blanks with the minimum number of ...
1
vote
0answers
26 views

Functions to obfuscate and deobfuscate String. Am I missing out any edge cases?

I have 2 functions, which are going to hide/ unhide the multiple languages plain text. Security is not a major concern. The objectives are Just want to find a way to hide multiple ...
3
votes
1answer
34 views

Validate URL with Regex and java.net.URL

I'm writing a URL validator. Firstly, it checks for special characters in the input. Secondly, it adds 'http://' and checks for validity. ...
2
votes
1answer
41 views

Function to convert “path” into regular expression

This function converts a string like: /{?lang(2-5):lowercase}/{page(2+):lowercase}/{article}-{id:integer}*.html* Into the following regular expression: ...
4
votes
2answers
66 views

Replace part of the string with n size with string of m size

I wanted to understand memory and pointers better before I endeavour into file path manipulations for larger project. This is simple replace part of the string test function that I need to rewrite ...
3
votes
1answer
142 views

Extract numbers from the head of a string in BASH script

In my current BASH script project I am processing a string, which cannot have spaces. At one point I get to where it is possible to have a series of digits. The series can be of any length, including ...
8
votes
3answers
645 views

Read string of any length in C

I've written code in C for reading a string of any length, and printing the string. It's one of my first C programs. I posted the program as part of a Stack Overflow question, and received a comment: ...
5
votes
4answers
1k views

Confirm the ending of a string

Challenge: Check if a string (first argument, str) ends with the given target string (second argument, target). This ...
9
votes
3answers
1k views

Insert str into larger str in the most pythonic way

I want to insert a small str into a larger one in the most pythonic way. Maybe I missed a useful str method or function ? The function that insert the small str into the larger one is ...
5
votes
1answer
77 views

Convert a hex string to base64

I wrote a program that converts a hex-encoded string to base64. It's my solution to the first of the Cryptopals challenges. My main concerns are: Portability. I don't want to rely on implementation-...
7
votes
2answers
104 views

K&R2 solution to exercise 1-18 (discarding trailing whitespace and empty lines)

Recently I have started learning C++ and I decided to learn C along the way to improve my understanding of how computers work. For C I am using "The C Programming Language Book" by Brian Kernighan and ...
9
votes
5answers
215 views

Stream text scanning

I've written some utilities to read text from streams. One of these, the ReadTo method, is to read text from a specified stream until a given text is encountered, ...
2
votes
3answers
82 views

Mapping words to letters which contains

Given sentence for example: ala ma kota, kot koduje w Javie kota I should to every letter occurring in the sentence I should map every string that this letter ...
5
votes
2answers
85 views
1
vote
0answers
41 views

Fast text search in Rust

I have a large file that I want to search for text as fast as possible. There is not a memory contraint, so I am loading the entire file into memory so that I can use the rayon parallelism crate in ...
4
votes
2answers
635 views

Writing 1.5 million rows in a file

I am generating SQL statements (of MySQL format) and writing into a file to create 10,000 tables. Each table contains 5 columns with 1.5 million rows of data in each column. I generated these data by ...
1
vote
0answers
48 views

Find text between two strings in data [closed]

I download a page to get it's source code. I then extract the first segment of the page that is between two strings that appear in the source code more than once. How can my code be improved? ...
0
votes
2answers
66 views

Random string generator that 'guesses' user inputted word [closed]

This takes a user inputted string, then tries to randomly 'guess' it. The problem is that whenever the input's length is 6 digits or more, it takes an incredibly long time to process it. Is there a ...
4
votes
2answers
107 views

Converting a set into a string

The input is a set of alphabets. The output is a string of 32 in length. For any letter in the set if it is preceded by a '¬' we replace the n-th character in our output string with '0', such that n ...
6
votes
3answers
397 views

LeetCode: Group Anagrams C#

LeetCode: Group Anagrams C# Given an array of strings, group anagrams together. ...
7
votes
2answers
68 views

Pythonic Substring Anagram Index

I'm working on improving my Python skills and have been doing a daily code problem. For the problem: Given a word W and a string S, find all starting indices in S which are anagrams of W For example ...
-1
votes
2answers
56 views

Format and return a string from a function in C [closed]

Write a function that will format a string and return it A fixed length of string is malloc-ed. snprintf is used to format the string and then the buffer is ...
7
votes
3answers
168 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
84 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
47 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
49 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
131 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
902 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
31 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
85 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
50 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
213 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
45 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
648 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
41 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
130 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
169 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
36 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
76 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
90 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
246 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
61 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 ...
5
votes
4answers
442 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 ...