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.
1
vote
2answers
43 views
Finding the largest word in the given String
If there are two or more words that are the same length, return the first word from the string with that length. I am a beginner. Could anyone highlight good and bad parts of the following ...
-2
votes
0answers
22 views
C++ Copy Construtor…copies fine but has unexpected core dump [on hold]
I have tried about everything. Increasing the amount of allocated space...copying not the full previous array. Testing has revealed that everything is fine until directly after the code is run. My ...
4
votes
2answers
745 views
Funny String Java Solution
I'm a little rusty in Java, but I'm using it to get ready for interviews. Here's the problem description from HackerRank:
Problem Statement
Suppose you have a string \$S\$ which has length ...
1
vote
2answers
47 views
Increment number in jQuery
I have this number returned from an Ajax request: 015-0011-00001. I want to increment the last part of the number (00001) on ...
5
votes
1answer
69 views
Palindrome using stack
I recently started learning Java, algorithms, and data structures. I am trying to check if a string is palindrome. I would like a review to see where and how I could improve.
...
4
votes
2answers
102 views
Find palindrome in a string
The purpose of this code is to find the largest palindrome in a string. It works fine when the string is short, but every time I test this code with 1000+ characters in a string, it takes forever to ...
9
votes
5answers
150 views
Return the longest word (or words) in a string
I'm coding for a function that checks the longest word (or words) in a string:
If multiple words are of the same size, those words have to be displayed.
If a single word is inputted, that word has ...
2
votes
1answer
23 views
Aligning text in Haskell
This Haskell program just aligns the text lines on the given substrings.
I took inspiration from here, but my code is not golfed.
...
7
votes
5answers
642 views
Creating a numeric phone keypad
I'm writing a Telephone class and it has a method called getDigits which takes in a String parameter and returns the number that would appear on your phone if you ...
-1
votes
0answers
23 views
3
votes
1answer
27 views
Greasemonkey script to refresh page until target string is found
I've been working on this user script to hunt for a specific string in an HTML webpage with the goal of finding the time at which it appeared. This feels needlessly complicated and I would like ...
8
votes
1answer
60 views
Replacement string Base64 (and a Base32) conversion
This provides (my own) implementation of ToBase64String and FromBase64String (since the .NET implementations suck), and a ...
1
vote
2answers
39 views
Clean regex matches with named matches
I have a regex pattern that will match some elements from a string and give them a particular name. For example, #^(?<foo>.*)^# will match the whole string ...
4
votes
2answers
64 views
Finding patterns in a string
I'm trying to find patterns of different length in a given string. How can I improve it? Are there problems?
...
3
votes
1answer
36 views
Length prefixed strings in C [closed]
In want to implement length prefixed strings in C (not null terminated), with some idiosyncrasies: malloc is prohibited, memory efficiency is important, each string (except for literal-backed ones) is ...
2
votes
1answer
54 views
StringRef - read only std::string like class similar to boost::string_ref
Idea behind the class is same as boost::string_ref or llvm::SrtingRef.
StringRef is immutable and not-owning.
I did not ...
7
votes
3answers
342 views
Count every word occurrence from file
How good is this algorithm? Personally I think it's over-complicated and needs some improvement. Should I be using iterators here (I think it's "harder" this way) or indexing? Should I stick with a ...
6
votes
2answers
131 views
Fastest C++ code to get common prefix length
In a C++ program, I have the following function to find the length of the longest common prefix between to char arrays a and b. ...
4
votes
1answer
58 views
Vigenère cipher 2
The following program is an updated version of this question, an implementation of the Vigenere cipher in C. It has been updated to take input from stdin and pipes, ...
2
votes
1answer
21 views
mIRC scripting like string token manipulation in Lua
I'm trying to reproduce in Lua the mIRC scripting manipulating tokens function:
...
0
votes
0answers
36 views
Permutation and sorting of Strings (parentheses problem similarity)
This algorithm runs in \$O(n!)\$ time and I wish I could make this a bit faster for larger elements.
Is there a better approach to solving the parentheses problem in shorter time?
...
2
votes
1answer
20 views
String Concatenation in Scheme
As plain r5rs is lacking in useful string processing utilities, such as string-split and string-join (I'm using MIT/GNU Scheme), I decided to implement my own. My procedure, string-join, works just ...
4
votes
1answer
204 views
Vigenère cipher in C
For my second major project in C, I decided to write an implementation of the Vigenère cipher in C.
My program uses command line options (optarg) and can read from both a file or from a string ...
2
votes
0answers
60 views
Validating Card Number in Delphi
As part of processing card payments, before even attempting to process, I need to check and validate the card number to make sure it's valid. For this, I've encapsulated this validation in a record ...
4
votes
2answers
46 views
Print the length of words as input as a histogram with horizontal bars
Input
A list of words separated by any number of spaces.
Output
A horizontal ASCII art histogram, where the n-th line is composed by as many asterisks (*) as the ...
3
votes
2answers
99 views
Brute-force string generator
I have created a brute-force algorithm class in C# and I was wondering if I could speed up the process of creating a new string. There are two methods inside the class: one returns the brute-force ...
7
votes
3answers
119 views
Check a string for any occurrences of certain character classes
This is a warm-up programming exercise for learning string methods in Python from HackerRank:
You are given a string S.
Your task is to find if string ...
8
votes
3answers
309 views
ASCII value converter
I have written VERY simple code that converts a string to a character array and then displays the ASCII value of each character. Let me know if this is the most effective/safe way of doing what I ...
1
vote
4answers
127 views
Find the longest sequential same character array
I am a new guy to Java. I want to find the longest sequential same character array in a input character arrays.
For example, this character array:
bddfDDDffkl
...
4
votes
2answers
60 views
Function that shortens a String based on a term/abbreviation mapping with special cases
This is a update of this question since the requirements for this task changed.
I have a function that takes a description as a String and returns a shortened ...
2
votes
1answer
34 views
Ruby-like squish in Haskell
squish is an onomatopoeic string function provided by Ruby on Rails that works on strings.
Given a string, squish condenses all ...
4
votes
4answers
89 views
Efficiently concatenate substrings of long list of strings
I am having performance problems with the following python function:
...
20
votes
4answers
3k views
“ONCE”, “UPON”, “A”, “TIME”
I'm working on a small program to perform various tasks on text content, primarily at the word level. I wrote these methods as ways to help prepare the raw text file into something more malleable, ...
8
votes
0answers
39 views
POSIX shell compatible and POSIX conforming dirname implementation
The discussion in the comments of this answer made me wonder how hard it would be to write a built-in only version of dirname.
This is what I ended up with but I'm ...
6
votes
2answers
96 views
Reading awkward text fields
I have written nested while loops to read in some of the columns in a text file that looks like this:
...
7
votes
3answers
145 views
Finding the shortest excerpt that contains all search terms
Write a function called answer(document, searchTerms) which
returns the shortest snippet of the document, containing all of the
given search terms. The ...
6
votes
4answers
299 views
Getting a scrabble score from a word
My program is complete and runs, and gives me the output I expect. For example, if I enter the string "HELLO" I should get 8. ...
6
votes
1answer
104 views
Random String Generation - Base36 and optimization
This is some fairly heavily optimized C#. Aside from reading like C++ code due to all of the pointers, does this pass sanity checks, and is there any way to improve it, while keeping its speed (or ...
6
votes
4answers
71 views
Join strings with different delimiters and some possibly empty strings
I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should ...
6
votes
1answer
75 views
Cleaning up HTML created by users
I have a system that accepts free text from users. This can either be plain text or a heavily limited subset of HTML. I've written the below with Html Agility Pack and Microsoft's AntiXss library. I ...
4
votes
2answers
52 views
Prompt user for input then create an acronym from it
My program is complete and working, but I would like second opinions on it. The program prompts the user to enter something like a phrase or some words. Then it will create an acronym of what was ...
5
votes
1answer
85 views
C implementation of a string
As C does not have a native string type, I decided to try making a similar type. It's not perfect by any means, so I was coming here to see what I could do to ...
5
votes
3answers
234 views
String to Array formatting
I'm tying to convert from this formatted string:
$filtersStr = "id:1||name:alex";
to:
['id' => 1,'name' => 'alex']
...
3
votes
1answer
52 views
Twisting words! (boustrophedon formatting)
I decided to implement properly the Code Golf challenge about twisting strings. I report the assignement verbatim for convenience:
Twisting Words!
Given a string and a positive integer. You ...
4
votes
2answers
87 views
Palin Pairs (Pallindrome Counting) Code
In an array of strings 'a' having 'n' strings i have to select the Palin Pairs from the given strings .for ex for input 3 bba abb abb Output=2
I am getting correct output but want to reduce time ...
7
votes
1answer
68 views
Print array of sentences vertically
Suppose I have an array of sentences:
[ "How To Format", "put returns between paragraphs", "for linebreak add
2 spaces at end" ]
I want to print it like this:
...
2
votes
1answer
80 views
Function to compare phone numbers
I got rejected in tech screen yesterday. I was asked to write a JavaScript function and send it over email. The question was(I have added the full question below). I have also added hiring manager's ...
6
votes
3answers
347 views
Finding the postion of a substring in a string
I am given two strings and return the position if in the larger string the smaller string is found. If not I am returning -1 for position. Any suggestions for improving my code.
...
6
votes
1answer
60 views
printf-style string formatter
As part of a larger project I'm working on, I've made a function that aims to replicate, as best as I can, the placeholder part of the console.log() function usable ...
8
votes
3answers
379 views
n number of x on the y
Everyone knows "99 bottles of beer on the wall".
Mat's Mug made a comment about mugs on the wall in The 2nd Monitor and I realized I never wrote a "beer on the wall" program. But that seemed way too ...