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.
3
votes
4answers
522 views
Custom algorithm for hashing and un-hashing password
I am attempting to create functions for getting an algorithm, hashing and un-hashing a string.
As it stands, it works, and very well. But, I feel this is not secure enough and someone could easily ...
15
votes
6answers
905 views
Find the longest word's length
The challenge is simple:
Return the length of the longest word in the provided sentence.
The solution is just as simple:
...
4
votes
2answers
34 views
Finding max depth of nested parentheses
The following code finds the max depth of nested parentheses in the given string - for example, for {}{}{{}} it outputs 2. If the given string doesn't contain ...
11
votes
3answers
840 views
Safe strcpy implementation with C++
After reading this article, I've decided to take a crack at implementing a "safe_strcpy" function that would remove some of the errors that the author speaks about. Obviously, my ...
4
votes
2answers
211 views
Function to split either a string array or string into a string array
I am programming a language interpreter in c# recently and i have created a set of functions that receive either a string or a string[] and splits it by a received string.
For example: with a string
...
5
votes
2answers
86 views
List all repeated substrings with a fixed length
While fiddling around, I've made a very simple and naive function to retrieve any repeated sub-string within a certain string.
...
8
votes
1answer
62 views
Address filter with PHP using regex
I developed a PHP function to get a not formatted address and split it in a street name and number.
Following are some patterns of received addresses
StreetName Number
SrtreetName, Number
Number ...
7
votes
2answers
81 views
Repeating a std::string n times
I recently posted an answer to this SO question as I did not think any of the current answers were satisfactory (most don't even answer the question!). I was wondering if anyone could offer any ...
6
votes
2answers
56 views
Quicksort for strings in Java
I have this implementation of Quicksort for strings. The algorithm sorts the requested range by first character, then by second, third, and so on. (Please, do not confuse this with radix sort; it is ...
6
votes
1answer
37 views
Anagram Substring Search
I am having difficulty understanding the runtime and space complexity while implementing the said question.
Following is the code:
...
8
votes
1answer
104 views
Simulating image transfer over noisy channel with a repetition code
I need to write a software in JAVA which allows me to simulate the transfer of some images over a noisy channel while adding redundancy with a repetition code
.
Before going into code details and ...
5
votes
1answer
84 views
Function to convert a decimal number as a string to hexadecimal
I am designing a cipher and need to convert between bases repeatedly in a loop. I have optimized the everything else, but I'm not too familiar with C++ code, and and am trying to figure out how to ...
10
votes
3answers
93 views
Counting characters
I'm a beginner at coding, and I am looking to improve the structure of how I write code and will take any tips. Posted a simple program that takes your name as input, then runs the string through a ...
3
votes
2answers
95 views
Scan first and last name from user, then format the name as last, first initial
Reads the user's first and last name (an entire line as a single string), then prints the last name followed by a comma and the first initial. Ensure the code re-prompts until the user types a name ...
4
votes
1answer
52 views
Determine if all characters are unique in string: Without using Bitwise operator
I am implementing the said question on "Cracking the Coding interview" using HashSet. Please have a look and suggest how I can improve the efficiency of the ...
4
votes
2answers
89 views
Splitting strings in C
I have created some code to split strings. The code will split the given string by the given delimiter into an array which is inside a struct it returns.
I am using ...
5
votes
1answer
59 views
Concatenating strings of equal length
My problem is this: Given two strings, append them together and return the result. However, if the strings are different lengths, omit chars from the longer String ...
11
votes
3answers
488 views
java if `String` begins with “red” or “blue”
Given a String, if the String begins with "red" or "blue" return that color String, ...
8
votes
2answers
143 views
C hack: replace printf to collect output and return complete string by using a line buffer
I have this great C program I'd like to embed into an iOS app. One passes command line arguments to it and the results are printed to stdout via ...
11
votes
1answer
132 views
Determine differences between two Strings, for use in undo/redo feature
I made a library that adds undo/redo functionality to EditText widgets in Android. It came from problem I had building text-editing apps that deal with large ...
4
votes
2answers
82 views
Function that produces \$a^nb^nc^n\$
I'm trying to write a function that produces an infinite list containing strings of the form \$a^nb^nc^n\$.
My first idea was to do it using comprehensions.
...
9
votes
4answers
345 views
Title case a sentence function
I am new to programming. I have written a solution in two different ways, but would like to know what is considered a better solution, and why.
Additionally, in terms of performance, why would one ...
0
votes
2answers
34 views
Differences in word counts in two files
How can I change my two functions to be more readable functions (i.e. in steps), because I am using pycharm.
...
8
votes
5answers
1k views
Reverse last 2 chars of a String
I have this problem:
Given a String of any length, return a new String where the last 2 chars, if present, are swapped. My ...
4
votes
2answers
29 views
Extracting components of a filename
I have a string str ="/Users/user/Desktop/task/U6342_Account_20150112.txt"
I need return only U6342_Account_20150112 as an ...
3
votes
1answer
59 views
Bracket Pair Validation
Validate that the following bracket pairs [], {}, () open and close successfully in a ...
5
votes
4answers
113 views
Implementation of cstring wrapper class
I want to have a thin wrapper (low overhead) around c-style string. Also, with some additional features like == and < ...
6
votes
2answers
287 views
Reversing a domain name string in Java
Given a dot separated domain name, reverse the domain elements.
Example:
...
9
votes
5answers
155 views
Reverse a domain name string
For an interview question, I was asked to do the following:
Given a dot separated domain name, reverse the domain elements.
Here are a few input/output examples:
...
8
votes
4answers
376 views
Determine the winner of a coin flip game
While I was writing this I had some thoughts and questions going through my head about if I was doing this in a good manner. For instance, is it good to use a ...
11
votes
6answers
769 views
Converting strings to PascalCase
I have a method which I use on occasion to convert strings (like enum and property names) to PascalCase for display.
It's ...
3
votes
1answer
38 views
Pattern in string count for C
I am trying to write a function that will count the occurrences of a pattern in a string without overlap. This is what I have right now.
...
8
votes
6answers
242 views
Substring function in C
I am trying to implement substring in C. How efficient and standard is this code? I have a hard time understanding how C functions are usually meant to work, like how ...
2
votes
1answer
452 views
Advent of Code - Day One
I tried to write a foolproof function for the first part of the first problem on adventofcode, which asks for the count of ( characters minus the count of ...
3
votes
1answer
35 views
Finding the largest not-necessarily contiguous alternating binary string after inverting any sub-string from a given string
I'm having problems solving this problem within the time limit.
Alternative Thinking
http://codeforces.com/contest/603/problem/A
Kevin has just recevied his disappointing results on the USA ...
6
votes
5answers
796 views
Memory-safe file-reading in C
I am trying to write a single function that will read a certain number of bytes from a C file, or the entire file, based on the arguments. I want it to be memory-safe of course, and deal with ...
8
votes
6answers
1k views
Find if the string contains ALL the vowels
Problem:
You are given a randoms string containing only lowercase letters
and you need to find if the string contains ALL the vowels.
Input:
First line contains N , the size of the ...
12
votes
2answers
98 views
Re-arranging an obfuscated address
I'm getting address (physical address, not digital) input that's obfuscated, and looks like the following:
The plaintext version:
...
1
vote
3answers
94 views
Longest common subsequence (LCS) for multiple strings
How would you improve this code? Particularly the check and check_all functions?
The time complexity of the algorithm of mlcs is \$O(|\Sigma|MN)\$, where \$\Sigma\$ is the alphabet, M is the number ...
5
votes
1answer
89 views
Find the first unique character in a string
Implementation for a relatively basic programming challenge:
Find the first unique character in a string
So evaluating the string ABCA would return ...
12
votes
2answers
634 views
Loop round and remove the consonants
The main objective of this code is that you must accept an input from the user and loop and remove the consonants and vice versa and display the new word.
I know there is a easier way of doing it, ...
7
votes
3answers
201 views
Reverse the character order of the words in a string
I've been trying to learn Java and one way I've been teaching myself is by tackling "programming challenge questions".
One such question is "reverse the character order of words in a string".
For ...
2
votes
3answers
103 views
English to Entean (V2) with maketrans
I wrote a python script that converts English to Entean language from an anime called "The Devil is a part timer".
This is the second version of the script which was first posted here Translating ...
5
votes
4answers
349 views
Processing a list to build an ip in a string format
The point of this code is to build an ip from a list of type ushort.
...
12
votes
2answers
112 views
“Vc” as in Vancouver, or Valencia?
It is common to shorten city names when writing, or at least in Sweden.
"Göteborg" (Gothenburg) is often referred to as "Gbg"
"Uddevalla" is commonly written as "Ua"
"Trollhättan" is often written ...
11
votes
4answers
358 views
Split a string into chunks of the same length
Inspired by this question in chat
Is there an easy way in .NET to split a string into an array by pulling chunks of the text in. I.e. I have an 18 character string I would like in 3 6-character ...
19
votes
4answers
1k views
Translating from English to Entean
I wrote a python script that converts English to Entean language from an anime called "The Devil is a part timer". I am sloppy at coding and know that the script can be made better.
In the anime, the ...
7
votes
2answers
467 views
Text message “reverser”
I decided to step out of my comfort zone (Java) and try out Python. I wrote a very simple reverser.py and want it to be reviewed.
...
3
votes
1answer
43 views
Inserting a parenthesized nickname
Given two strings, for example
s1 = "Valentino Rossi" (which may contain as many spaces between the 2 words as I like)
s2 = "Vale"
I have to create a function that requests these two ...
3
votes
1answer
21 views
Given a string, print another one without a given char
My aim is to write a C program (I must create a function) that, given a string and a character, returns another string without the given char value.
For example: ...