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.

learn more… | top users | synonyms (1)

2
votes
1answer
17 views

Swift solution to Leetcode “Longest Substring Without Repeating Characters”

From LeetCode medium 3. Longest Substring Without Repeating Characters: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
17
votes
3answers
3k views

What does the Bob say?

Description: Bob is a lackadaisical teenager. In conversation, his responses are very limited. Bob answers 'Sure.' if you ask him a question. He answers 'Whoa, chill out!' if you yell ...
3
votes
2answers
70 views

Parsing a string with named sections and a key-value pair on each line

I have a response String as shown below which I need to parse it and store it my class. Format is shown below: task name followed by this dotted line ...
1
vote
0answers
12 views

Password Entropy in Lazarus (Delphi-like)

My today's goal was to create a function, which would evaluate the entropy of a given string password. It's mostly about how random the password is. This little code is based on the C# code from Jeff ...
4
votes
1answer
47 views

Alternate letters to UpperCase

As an exercise I repeated this Java question, but in Go: Convert string to mixed case The objective is for every second letter to be converted to uppercase. Go string processing is relatively new to ...
2
votes
3answers
142 views

Convert string to mixed case

This method converts a string to mixed case, id est mixedCase("hello, world!") -> "HeLlO, wOrLd!". ...
4
votes
2answers
43 views

Counting from 0 to a number and back to zero, and space-padding the result to be a given length

I completed a task: The objective was to create a method with 2 arguments: a number to count to, and how many char/numbers in the resulting string. Result: Let's say that "number" is 5, so it will ...
-1
votes
2answers
35 views

Find multiple keyphrases from a text

I have keyphrases abc, xyz, pqr, mno, etc. Text - " this text contains abc and mno", want to find whether text contains keyphrase string. I am looking for an efficient solution. ...
1
vote
2answers
41 views

Finding palindromes and the longest word in a string

I have two little projects that I've been working on. One is to find all palindromes: ...
5
votes
1answer
46 views

Lazy String splitter in C++

I created a string splitter in C++. It splits a string in a lazy fashion and makes use of forward iterators to sequentially supply the next token from the string until it runs out of tokens. ...
1
vote
1answer
34 views

Alternative to using strncpy() as 'safe' version of strcpy()

I am thinking of using this as part of a header file to give me a useful string-manipulation tool. Elements is size of dest to prevent overflow: ...
4
votes
4answers
270 views

Removing duplicate characters from a string

I implemented a function removeDuplicates which takes 1 parameter, a std::string, and returns a ...
0
votes
2answers
68 views

Student class with std::string

I am writing a class that has a few std::string as a member. I can't find clear guidelines on how use them in a safe way. Are ...
3
votes
1answer
52 views

Determining if a string is a palindrome of a permutation

I wrote code to determine if a string is a palindrome of a permutation. This exercise was taken from Cracking the Coding Interview. I'm looking for any tips on improving it. ...
0
votes
4answers
119 views

Remove “b” and “ac” from a given string

I coded this solution for this problem: Given a string, eliminate all “b” and “ac” in the string, you have to replace them in-place, and you are only allowed to iterate over the string once Seems to ...
16
votes
5answers
2k views

Word Inverter in C

I've just made this program and I want to know how to improve it. It just receives a word and prints it backwards. Sequences of numbers are also accepted, but not white spaces (that's why I used ...
0
votes
0answers
33 views

Is this implementation of memcmp() correct in python [closed]

I was trying to implement the memcmp(). I wanted to know whether I have accounted for all the edge cases. Can it be really used(not considering performance constriants) as a drop-in replacement for ...
5
votes
2answers
77 views

x86 assembly method that mimics strcat

I'm trying to learn x86 assembly and hopefully move on to projects of the scope that more than one person would be involved. This is a (relatively) simple subroutine written in Intel x86 assembly ...
5
votes
1answer
61 views

run command pipeline in C

This code parses and tokenizes my shell language command interpreter. I will try and make it 2 functions, one that is the tokenizer and the other that is the rest of the function. Can you find ...
-1
votes
1answer
51 views

Determining whether a string can be rearranged into a palindrome

For a string, count the number of occurences of each character. If at most one character has odd count then the string can be a palindrome else it's not. ...
2
votes
1answer
57 views

Parsing in between of brackets

I do parsing of the string in order to find wrapped sub-string inside brackets of the first level. a+(b+(d-g))+g+d, in this case I will need to separate ...
4
votes
2answers
125 views

My implementation of String in C++

I wrote my string class. The code works, but could anyone tell if I am doing anything wrong? It is an exercise from the "Accelerated c++" book: Implement the Str class, but choose an ...
1
vote
1answer
47 views

Levenshtein distance with edit sequence and alignment in Java

I have this program that computes a Levenshtein distance of the two input strings, their edit sequence, and the alignment: LevenshteinEditDistance.java: ...
2
votes
2answers
50 views

JavaScript function to convert underscore-case to camel-case (and vice-versa)

Actually I needed a function which converts underscore to camel-case. But then I've had the idea: Why not extend the function so, that is works the other way around? Finally I recalled that there is ...
3
votes
1answer
38 views

Anagram counter

Homework prompt was: You are given two strings, a ‘parent’ string and a ‘query’ string respectively. Your task is to determine how many times the query string – or an anagram of the query string ...
5
votes
1answer
75 views

An extension to the StringBuilder

This is another pretty basic class I wrote for a library as I hate the way the default StringBuilder in .NET works. Essentially, I wanted to have the ...
1
vote
0answers
31 views

Given an array of strings, group the anagrams together

Scan the array of strings, for each string get the code(which is nothing but the summation of char values of the string) and add the string to TreeSet<String> ...
4
votes
1answer
87 views

Finding number of times each string in an Array of strings occurs in a large stream of characters (i.e large string)

Interview problem: Given a stream of characters (e.g. acacabcatghhellomvnsdb) and a list of words (e.g. ["aca","cat","hello","world"] ) find and display count of each and every word once the ...
1
vote
1answer
33 views

Given an array of Strings , check if they are anagrams are not

Two strings are anagrams if they are permutations of each other. Assuming we have an ASCII alphabet we can take 128 integer array to count the characters in the first string. Then decrement the count ...
3
votes
1answer
26 views

String Matching w/o repeating the comparisons for common part of the two strings

In an attempt to think up a more efficient String Matching algorithm than the naïve \$O(n \cdot k)\$ one I came up with a slightly modified approach. In my algorithm (code in Java), I tried a little ...
2
votes
1answer
57 views

String-casting utility functions

I wrote a small header that is supposed to take care of calling the right strtoX or or stoX function for me and doing so at ...
3
votes
2answers
60 views

Simple function to generate an HTML-safe string

Sometimes, we have to do some fixing to insert a string into an HTML property. Or just to display it. But not everything is safe! Consider the following example: ...
11
votes
2answers
1k views

One-way hash using ASCII

Assume the built-in function Ascii(c), where c is a one character string, will return an integer containing the ASCII value ...
-1
votes
1answer
37 views

Replacing address details in colon delimited string

I'm sanitising personal data in a large database with a series of Regular Expressions. In many cases the sensitive data is in a colon-delimited field within a CSV file. Here is a sample: ...
0
votes
2answers
44 views

Extracting data from a string

I created a method that takes a string value with a fixed length of 9 characters and extracts three values, house (4 characters), ...
2
votes
1answer
42 views

Counting occurrences of “hi” in a string, except where followed by “x”

I already solved this one from CodingBat, but I'm unsatisfied with my solution and I feel I could have made it much shorter. Most of the other recursion tasks could be solved by a one line conditional ...
6
votes
3answers
348 views

Sorting a String based on its words

Is there a better, more efficient or nicer way to do this? ...
0
votes
1answer
29 views

Comparison of incoming error strings to known set and transformation into 3rd string

I have a function where I am comparing an error string returned from a web service to several lists of known strings, and then based on which list the error is a member of, returning from the function ...
2
votes
2answers
75 views

Constructing a 4×4 grid of words

I have an ArrayList which contains Strings with a size of 1000. I am looping through that ArrayList and finding words and trying to form a square from them. For example as follows: ...
3
votes
1answer
35 views
-5
votes
1answer
66 views

Reverse a string [closed]

I use this for reversing a string, but it has O(n) : reverse(y.begin(),y.end()); How can I reverse a string in O(n/2) ?
5
votes
1answer
61 views

K&R 1-20 Solution

I'm currently reading the infamous K&R C book and trying to solve Exercise 1-20. My solution looks kind of too simple, but it works. I've searched the web for different solutions, but they all are ...
2
votes
1answer
32 views

Color String Macros and ports of useful PHP string functions

Here is a code file (I use it as a stand alone header file to be included in my projects) that contains macros to generate ANSI encoded strings that when printed are colorized. Also, the module ...
4
votes
3answers
540 views

Eval is evil: Dynamic method calls from named regex groups in Python 3

I'm working on a simple dice roller for a Python IRC bot. The particular game this roller is for uses six different kinds of dice, which I've defined using a simple base class, and created six ...
2
votes
2answers
102 views

Given a string S and Q query strings(q1,q2,…), check for each query string whether or not it is sub-sequence of S

Here is my approach. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. ...
1
vote
2answers
54 views

Checking whether a string ends with one of a list of suffixes

I want to check if some line ends with any substring defined in some list. Is there a better way than following one? ...
9
votes
2answers
599 views

Comparing two strings to see if string 2 is inside string 1

Here is what I have to do: Write a function scramble(str1,str2) that returns true if a portion of ...
4
votes
3answers
209 views

Finding the fastest common prefix of 2 strings in Python

I'm comparing my algorithms, slice_prefix and bit_prefix, with existing ones to find the common prefix length of 2 strings as ...
3
votes
2answers
66 views

Comparing a string using a stack

Let L be the language defined as follows: The words are made up of strings of a’s followed by b’s. The number of a’s is always equal to the number of b’s. Examples of words that belong ...