Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Thursday, January 15, 2015

How to sort string in javascript

How to sort string in javascript

example If you have an array of string, and you want to sort it.how to do ?
1. simple array
var pets = ['cat','snake','dog'];
pets.sort(function(a, b){
       if (a > b)
              return 1;
       else if if (a.n == b.n)
              return 0;
      else
              return -1;
});
your data will be sort like this
  • cat
  • snake
  • dog

2. table data
if you have data like this table, you want to sort by name
nameage
sammy12
tony51
lucy20
// fill in array
var ages_list = [];
ages_list.push({"name":"sammy","age",12});
ages_list.push({"name":"tony","age",51});
ages_list.push({"name":"lucy","age",20});
//sort it
ages_list.sort(function(a, b){
     if (a.name > b.name)
          return 1;
     else if if (a.name == b.name)
          return 0;
     else
          return -1;
})
this is result of sort
nameage
lucy20
sammy12
tony51

Saturday, March 5, 2011

Best way to use string in vb.net programming


Best way to use string in vb.net programming


This is the very useful object that you can manage your string, especially when you want to concatenate your string in the loop.


Old:

Dim I as integer

Dim s as string

For I = 1 to 10000

S = s & "concat string"

next


new:
dim I as integer

dim s as new system.text.stringbuilder.

for I = 1 to 10000

s.append("concat string")

next


You will see a lot different when you have very long loop.

See more information here.