A string is a sequence of zero or more 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
2answers
49 views
How to refactor this Ruby method?
The new_string code in this method does not seem idiomatic.
The goal is to not mutate the string passed in, which I believe is a good practice.
This method changes all URL's in the string into an ...
0
votes
0answers
15 views
reading input from keyboard
I am required to read from an keyboard(stdin), the following text. Pl note that it will be entered by user from keyboard in this format only.
#the total size of physical memory (units are B, KB, MB, ...
0
votes
0answers
22 views
String Matching
I recently came across a lecture on DFA. I tried to use it to determine whether a given 'search string' is found in the 'input string'. Please tell me if there is a better way
(display "Enter input ...
0
votes
0answers
33 views
JavaScript regular expression literal as string literal
Please refer to this question for more discussion.
JavaScript string literal sometimes to many escaping slashes. The following address this problem by converting a regular expression literal into a ...
0
votes
0answers
41 views
Differentiating String/Int User Input [closed]
I am having issues trying to type code that will make my program distinguish whether the user inputs a string value or an int value. If an int value is typed in, it will be stored into an array (named ...
2
votes
5answers
317 views
String manipulation in Java
Here is the question followed by my program which works good
Given a string, return a version without the first 2 chars. Except keep the first char if it is 'a' and keep the second char if it is 'b'. ...
4
votes
1answer
76 views
Ruby: refactor simple string method for aligning DSV text
GOAL:
Accept DSV strings where the delimiter may consist of more than one character
Accept DSV strings where there are no embedded delimiters
Output text with no modification to the source string ...
-1
votes
0answers
33 views
Using for loop to get the Hamming distance between 2 strings [closed]
So i'm having some trouble with this code. i need to get the Hamming distance (the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols ...
1
vote
1answer
72 views
High School Java Class: Pong Project External Reviewer
Panelball class:
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Panelball extends JPanel implements Runnable {
private static final long ...
2
votes
1answer
60 views
Java - Is this the correct implementation of a timer/timertask to destroy a process that overruns a defined time limit
I was wondering if this is the correct implementation of a times task to destroy a thread after it overruns a predefined time period:
it works by creating a getting the thread from ...
2
votes
1answer
43 views
Generating random strings
I've created the following string manipulation function for randomizing my passed string in Lua:
require "string"
require "math"
math.randomseed( os.time() )
function string.random( self )
...
2
votes
1answer
41 views
LISP - Modify string
I have to write a program that changes a string's vowels, consonants and other symbols into C, V respectively 0. I've done this but I wonder if there is a more efficient and elegant way to do it. ...
1
vote
4answers
133 views
How could this postfix notation program be improved?
My postfix program allows the user two options one option for calculating a postfix equation:
* Confirmations after each input (after an input, the user is ask for another number, operator, or final ...
2
votes
2answers
116 views
string to integer (implement atoi)
Implement atoi to convert a string to an integer.
Requirements for atoi: The function first discards as many whitespace
characters as necessary until the first non-whitespace character is
...
1
vote
1answer
154 views
Faster JavaScript fuzzy string matching function?
I'm using the following function to fuzzy match strings:
function fuzzy_match(str,pattern){
pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; });
return (new ...
2
votes
1answer
132 views
JAVA, Twitter4j insert tags around entities in body
Because we're passing object to Spring Framework in which Jackson classes convert them into JSON as a reposnse we chose to Implement more simple Tweet class rather than the twitter4j provided Status ...
3
votes
3answers
111 views
Length of last word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is ...
3
votes
1answer
171 views
Dynamically allocated C strings in C++, concatenation, pointers, etc
I'm writing a small Win32 Console app that manipulates the contents of binary files. It accepts the filename as a command line parameter and writes to a file named filename.scramble
This is the first ...
3
votes
1answer
94 views
Crtitique my Haskell function 'capitalize'
I am a Haskell beginner. I wrote the following function that takes a string and returns a new string with each word capitalized: first letter uppercase, following letters lower-cased.
It works, but I ...
2
votes
1answer
197 views
Get metadata from an Icecast radio stream
I am new to Python and not very familiar with advanced Python data structures.
I have written a function to receive data from a socket in Python and perform string manipulations on it. The basic ...
2
votes
1answer
109 views
Too slow two strings comparer
I have 2 strings for example:
abcabc and bcabca
or
aaaabb and abaaba
I checked that second string is the same or not like first string but shifted.
bcabca = ..abca + bc...
Here is code it works ...
0
votes
2answers
114 views
Elegant function to “increase” a JavaScript string - for example, turning “aac” into “aad”
I'm writing a function to increase a string so, for example, "aac" becomes "aad" and "aaz" becomes "aba". The result is horribly inelegant, I can't get it simple enough and I feel I'm missing ...
3
votes
4answers
146 views
Can this string parse be improved?
My data is in this format:
龍舟 龙舟 [long2 zhou1] /dragon boat/imperial boat/\n
And I want to return:
('龍舟', '龙舟', 'long2 zhou1', '/dragon boat/imperial boat/')
In C I could do this in one line with ...
2
votes
1answer
118 views
Python 3: Finding common patterns in pairs of strings
I have written a piece of code that finds common patterns in two strings. These patterns have to be in the same order, so for example "I am a person" and "A person I am" would only match "person". The ...
3
votes
1answer
71 views
A reliable way to remove consecutive appearances of a substring
I'm attempting to write a piece of code that is supposed to remove consecutive appearances of a string (not a single character) in a StringBuilder.
It's extremely important that the method works well ...
0
votes
1answer
54 views
Skiena's Programming Challenge [UVa ID 10137]- Getting WA
Question from Skiena's Programming Challenges.
Getting WA (wrong answer) in Online Judge even though it's working for sample test cases. Can somebody find a case where it fails?
I tried the tricky ...
4
votes
3answers
283 views
Longest common substring
I wrote a program to find the longest common subsequence among several strings. I used a naive algorithm and implementation.
The motivation was solving the Rosalind problem at ...
2
votes
3answers
39 views
Flexible multiple string comparision to determine variable value
I've a web form that allows users to create clusters of three sizes: small, medium and large. The form is sending a string of small, medium or large to a message queue, were job dispatcher determines ...
4
votes
1answer
68 views
Nicely tabulate a list of strings for printing
I have a list of strings of variable lengths, and I want to pretty-print them so they are lining up in columns. I have the following code, which works as I want it to currently, but I feel it is a ...
2
votes
2answers
105 views
Trim function in C
I am trying to write an idiomatic trim function in C. How does this look? Should I instead malloc the new string and return it?
void trim(const char *input, char *result)
{
int i, j = 0;
for (i = ...
0
votes
1answer
39 views
split up a string into whitespace-seperated fields
I am trying to improve my C skills, and I hope someone might be able to provide me with some feedback on the following code. I avoid strtok function intentionally.
#define MAX_SIZE 1000
int ...
3
votes
2answers
92 views
String Building
Before, I had this code, sometimes it is longer:
String dbEntry = "idBldgInfo = '" + currentBldgID + "',scenario = '305',installCost='" +
installCost + "',annualSave='" + annualSave + ...
-2
votes
1answer
38 views
Most effiecient way to compare a string and an Array [closed]
I want to compare a string and an array like this,
string str1 = "Ceo, Hr, Coo, Mccal";
string[] str2 = new string[] {"CEO", "COO", "HR", "McCal","CSU","PSU"};
I want to check if str2 has a ...
0
votes
0answers
50 views
custom cmdline implementation
The below program takes the inputted string from commandline and parses it and calls the corresponding function.
commands are either single word or multiple words.
say for e.g.
-#version ...
2
votes
1answer
122 views
Inefficient usage of string.format?
I have some sample code where I used string.Format but after reading about benchmark performances by other people I believe that it may be better to do multiple appends by a StringBuilder
Here is the ...
1
vote
1answer
164 views
first non-repeated character in a string in c
Write an efficient function to find the first non-repeated character in a string. For example, the first non-repeated character in "total" is 'o' and the first non-repeated character in "teeter" is ...
0
votes
3answers
192 views
Run Length Encoding
Given an input string, write a function that returns the Run Length
Encoded string for the input string.
For example, if the input string is “wwwwaaadexxxxxx”, then the
function should ...
1
vote
1answer
138 views
Code review for recursion to map phone number to strings
I am trying to solve the following via recursion: In a phone we have each digit mapped to a number.
Example:
1 2(ABC) 3(DEF)
4(GHI) 5(JKL) 6(MNO)
7(PRS) 8(TUV) 9(XYZ)
* 0 ...
7
votes
4answers
282 views
Count words in a C string
I have a string that must be splitted into an array of strings so using strtok makes perfect sense but before that I want to allocate the array of strings and thus I count how many words in it.
...
4
votes
1answer
216 views
efficient looping procedure to find the longest common substring java
I retrieved 200 tweets using jersey API. I want to find two tweets which have the longest common substring. This is what I have got. tweetList is an ArrayList of Tweet Objects. comapreTweets method ...
8
votes
2answers
206 views
String join of distinct string
I have a class like this one:
class EmailClass
{
public string MailAdresse { get; set; }
public string MailAdresseCC { get; set; }
}
Through a JSON deserialization I obtain a ...
-1
votes
1answer
105 views
String.compareTo method to compare [closed]
I'm pretty new to java and don't really know about these stuff and it's my first time writing these methods! of course I have no clue how I can write them.
will you check my Method and let me know ...
0
votes
2answers
209 views
Given a sequence of words, print all anagrams together
Given an array of words, print all anagrams together. For example, if
the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output
may be “cat tac act dog god”.
My idea is to sort ...
7
votes
4answers
619 views
Reverse each word of a string in C
I had this interview question like a year ago, I was asked to code on a piece of paper how to reverse each word of a string. Since I am used to java I proposed the obvious answer of using split + ...
7
votes
1answer
92 views
Can I use string.Format to represent these formatted numbers more succinctly?
string taskNumber = order.ID.ToString("D6") + "-" + task.ID.ToString("D4");
I'm writing out two numbers separated with a dash. The first number is padded with leading zeros until 6 digits, the ...
5
votes
3answers
160 views
Java string replace
I am new to Java and I am trying to learn about optimizing code to make it production ready. I have the following code below. I would like to know how I could optimize it. I thought by using a small ...
1
vote
0answers
136 views
Print all interleavings of given two strings
Given two strings str1 and str2, write a function that prints all
interleavings of the given two strings. You may assume that all
characters in both strings are different
Example:
Input: ...
8
votes
3answers
343 views
Is this a proper way of programming in c#?
I have a menu, where a user selects one out of 4, and another 2 or 4 options will appear. I used big buttons; a picturebox + label to create the buttons.
The 4 main buttons are fixed, but the 4 other ...
4
votes
0answers
517 views
Print all permutations with repetition of characters
Given a string of length n, print all permutation of the given string.
Repetition of characters is allowed. Print these permutations in
lexicographically sorted order
Examples:
Input: AB
...
5
votes
2answers
714 views
reverse every word in a string(should handle space)
Examples:
char test1[] = " ";
char test2[] = " hello z";
char test3[] = "hello world ";
char test4[] = "x y z ";
Results:
" "
" olleh z"
"olleh dlrow "
"x ...
