Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 31503

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.

6 votes

Decompressing a string

I have taken a while to answer this question (I started, then work got in the way...). Now that I am back to it, I see that Simon has posted a good review... So, part 1, a review (and then later, a s …
rolfl's user avatar
  • 97.5k
10 votes

Determine if one string occurs at the end of another

Unfortunately your code has a bug. If there is a mis-match on the end-string, you roll-back the pointer for the end-string to the init value. You should also roll-back the pointer in the s string so t …
rolfl's user avatar
  • 97.5k
12 votes
Accepted

Code Hunter 2.06: Count occurrences of 'a' in a string

This is a nice short piece of code, though it has a number of 'features' which can be improved. Code Style Java code style recommends a lower-case letter to start method names.... Puzzle should be p …
rolfl's user avatar
  • 97.5k
10 votes

Eliminate duplicates from strings

Style Java Code-style conventions put: the { brace at the end of the line that introduces the compound statement block, not on the next line. spaces between variables and operators: for (int i=0;i<le …
rolfl's user avatar
  • 97.5k
4 votes

Replacing the occurence of the character in string

replaceHelperAlt(chars, i + 1, result); } } } The above solution has the benefits of: no unnecessary List instances and String instances are created (the only strings created are actual …
rolfl's user avatar
  • 97.5k
5 votes

Split camel cased/snake cased String

This has presented an interesting problem. Your solution concerns me, because it does not solve things the way I would. This, in itself, is not a problem, but I had to look through your code, and figu …
rolfl's user avatar
  • 97.5k
7 votes
Accepted

Counting the number of occurrences of chars in one string, in another string

The net result is that you have a performance of \$O(nm)\$ or \$O(n^2)\$ depending on whether there are more characters in the searchIn or searchFor strings. …
rolfl's user avatar
  • 97.5k
4 votes

Truncate String to target length using only whole words

Style if (s.length() > TARGET_LENGTH) { if (s.contains(SEPARATOR)) { if (s.substring(0, TARGET_LENGTH + 1).contains(SEPARATOR)) { return s.substring(0, s.substring(0, TARGET_ …
rolfl's user avatar
  • 97.5k
10 votes

Usage of StringBuilder for returning copies of a string

I am a fan of using primitives. In this case, the performance benefit would be minimal, but the number of copies would actually be less..... In reality, I would probably use the StringBuilder approac …
rolfl's user avatar
  • 97.5k
4 votes

Text tokenizer - extract words and positions from text

String.split is a special case of using regular expressions. Just because it does not return the position of the words, does not mean that regular expressions themselves are not the right solution. C …
rolfl's user avatar
  • 97.5k
4 votes
Accepted

Formatting an ID string

It is things like this which drive me nuts, and I agree with you, your solution is good, but ugly. Your solution is also probably close to being as efficient as possible in Java, using the StringBuild …
rolfl's user avatar
  • 97.5k
2 votes
Accepted

Extracting first initial and last name

Regular expressions are another option: $name = "Tom Smith" $short = $name -replace "(?<=^.).*\s", "" $short The above code replaces the second character, through to the last space, and replaces th …
rolfl's user avatar
  • 97.5k
5 votes

Returning a string representation of the number of albums and songs available

Text manipulation like that is always a pain. I like to extract functions for things like this, though. private static final String simplePlural (int count, String noun) { if (count == 1) { …
rolfl's user avatar
  • 97.5k
16 votes
Accepted

Reversing the digits of an integer

In Java, and in Code Review, the preference is for creating both highly readable, and highly efficient code. It is an almost bizarre fact, that one leads to the other. your code has one efficiency, …
rolfl's user avatar
  • 97.5k
5 votes
Accepted

Longest DNA sequence that appears at least twice (only one DNA string as input)

(never mind, no two strings will have the same length). Instead of if (a.length() > b.length()) ... and if (b.length() > a.length()) you should simply use an if (....) {....} else {....} …
rolfl's user avatar
  • 97.5k

1
2 3 4 5
8
15 30 50 per page