Category Archives: Uncategorized

How can I get last characters of a string using JavaScript?

You’ll want to use the Javascript string method .substr() combined with the .length property.

var id = "ctl03_Tabs1";
var lastFive = id.substr(id.length - 5); // => "Tabs1"
var lastChar = id.substr(id.length - 1); // => "1"

This gets the characters starting at id.length – 5 and, since the second argument for .substr() is omitted, continues to the end of the string.

If you’re simply looking to find the characters after the underscore, you could use this:

var tabId = id.split("_").pop(); // => "Tabs1"

This splits the string into an array on the underscore and then “pops” the last element off the array (which is the string you want).

Substr() in Perl…

It can be done as follows :-

Following is the example code showing its basic usage:

#!/usr/bin/perl -w

$temp = substr("okay", 2);
print "Substring valuye is $temp\n";

$temp = substr("okay", 1,2);
print "Substring valuye is $temp\n";

O/p

Substring valuye is ay
Substring valuye is ka

How add values to %hash in perl?

It’s as follows:

#!/usr/bin/perl
use strict;
use warnings;
use v5.10;

my @a=(1,2,3,4,5,6,9);
my @b=('q','w','e','r','t','y','u');
my %hash;
for(my $i=0;$i<7;$i++)
{
  $hash{$a[$i]}=$b[$i];
}

print $hash{'9'};

O/p

u

How to get the row number or rank of row in mysql?

It should be done as follows:

SELECT @x:= @x + 1 AS rank, title FROM t1 JOIN ( SELECT @x:= 0 )X ORDER BY weight

How to order contents using specific values in a field using MySql?

It can be done as follows:-

SELECT * FROM table_name ORDER BY FIELD(filed_name,"value_y","value_x") DESC