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.
-1
votes
0answers
17 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
votes
0answers
30 views
Program gives to a word special numerical value. I need help to upgrade my code [closed]
Program checks each letter of the string one by one and calculates the sum of the numerical values of each letter i have applied. I need your help to not let program count value of "i" teller if it ...
1
vote
1answer
60 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 ...
1
vote
1answer
27 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 ...
1
vote
0answers
20 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
31 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
127 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
106 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
106 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
116 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
109 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
119 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
93 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
139 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
109 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
99 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
66 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
43 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
212 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
66 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
98 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
36 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
36 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
49 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
113 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
115 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
159 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
131 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
273 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
192 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
193 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
99 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
202 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
534 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
90 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 ...
1
vote
0answers
126 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
489 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
667 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 ...
0
votes
2answers
128 views
symmetric string checking [closed]
I wrote this routine in C to check the symmetry of a string using only a stack.
(This is absolutely for educational purpose in our Theory Of Computation Class)
Anyways, does this look right?
For some ...
2
votes
1answer
62 views
Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26
I want to implement numbering scheme like Microsoft Word uses for numbering.
first one gets = A,next is B, next is C, .... then AA, then AB,....and so on.
as shown below
A
B
C
.
.
AA
...
4
votes
1answer
510 views
Parsing XML to create IList
Here's a class I created to parse XML to create an IList.
It seems to me that this is something that will be done a lot in general by a lot of different programs. Is there a more standard way of doing ...
4
votes
4answers
193 views
Title case name when first,middle and last are all upper or lower case
This code works, but i get the feeling that it could be shorter and simpler. Any ideas?
private void CheckNameCase(Models.PersonalInformationModels.PersonalInformationModel model)
{
// if first ...
3
votes
2answers
617 views
CoffeeScript date formatting
forceTwoDigits = (val) ->
if val < 10
return "0#{val}"
return val
formatDate = (date) ->
year = date.getFullYear()
month = forceTwoDigits(date.getMonth()+1)
day = ...
4
votes
2answers
1k views
Reading a line from a text file and splitting its contents
I have this kind of file structure
MALE:FooBar:32
FEMALE:BarFoo:23
Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>
try{
BufferedReader in = ...
6
votes
5answers
5k views
C++ program to count the number of occurrences of a word
I was selected for the third round of MS internships for third years. We were surprisingly asked a very easy question: “Make a program that counts the number of times the WORD "a" or "A" occurs”. I ...