Tagged Questions
3
votes
1answer
41 views
Trim certain characters from a string in javascript
I want to remove not only spaces, but certain characters aswell from the beginning or end of a javascript string.
function trim(str, characters) {
var c_array = characters.split('');
var ...
1
vote
1answer
29 views
Implementation of String object as an exercise
I am reading "Object-Oriented JavaScript" by Stoyan Stefanov to learn JavaScript and in the end of the chapter named "Objects", there's an exercise that asks you to implement your own String object. I ...
3
votes
1answer
79 views
String processing in JavaScript
We have a lot of phone numbers that contain dashes and start with a zero which are from another country.
I am trying to strip the dashes and the one leading zero and select the country code from a ...
0
votes
0answers
47 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 ...
1
vote
1answer
361 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 ...
0
votes
2answers
127 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 ...
2
votes
1answer
76 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
...
3
votes
2answers
983 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 = ...
0
votes
2answers
42 views
Javascript Repeating Method… Better way to do this?
I'm sure there's a better way to approach the following. I'm writing a plugin. Users can enter settings in the following foramt: setting: "object1setting -> object2setting", It's done this way to ...
2
votes
1answer
237 views
How can I improve performance for my JavaScript table class?
I've written a JavaScript table class to make it easy to display tabular data and allow the user to sort the data by clicking on the table headers.
However, when there are hundreds of rows, ...
5
votes
2answers
222 views
String manipulations: transform “a-b-c” into “a(b(c))”
function dashesToParentheses(str) {
var list = str.split('-');
return str.replace(/-/g, '(') + repeatString(')', list.length - 1);
}
function repeatString(str, times) {
if (times == 1)
...
2
votes
3answers
659 views
String.IsNullOrWhiteSpace in JavaScript
I am aware of it being frowned upon to do something like write C# in JavaScript. (See Write Cobol in any language if you don't know what I'm talking about.)
But as a judgement call I think we could ...
3
votes
3answers
196 views
Improving the code to turn a string into an array of numbers?
I have a string of numbers, like "31654918562314", and I want to convert it into an array of integers. The code I've written is:
string source = "31654918562314";
int[] numbers = new ...
0
votes
1answer
129 views
Making an encoding function faster
I currently have this encoding function which simply subtracts one from each character code:
String.fromCharCode.apply(null, text.split("").map(function(v) {
return v.charCodeAt() - 1;
}));
...
8
votes
2answers
8k views
Pack and unpack bytes to strings
I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string that ...