Search This Blog

Thursday 18 February 2016

Split String at Space ,Except if it is not in double qoutes


Split String at Space ,Except if it is not in double qoutes


 public class Main {
    public static void main(String[] args) {
        String str= "abc \"peter micheal\" Jean \"Patrick David\" Richards";
        String[] tempArr = str.split("[ ]+(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
       for(String string : tempArr) {
         System.out.println(string);
      }
  }
}

You can use online java compiler such as THIS to verify usability.
This will help you to avoid chances of using wrong solution and save your time.

Output: 

abc
"peter micheal"
Jean
"Patrick David"
Richards

Monday 8 February 2016

Set Focus on any table row in javascript

                     Set Focus on any table row in javascript


To set focus on any specific row we will require row id ,HTML : 


<div id="one"><table border='1' id='tableDiv1'><tr><td>row1</td><td>Test1</td></tr><tr><td>row1</td><td>Test1Test1</td></tr><tr><td>row1row1</td><td>Test1Test1</td></tr><tr><td>Selected Row</td>Selected Td<td></td></tr><tr><td>row1</td><td>Test1Test1trgTest1</td></tr><tr><td>row1row1</td><td>Test1Test1Test1Test1</td></tr><tr><td>row1row1</td><td>Test1Tertgrgrst1Test1Test1</td></tr><tr><td>fdetgregtt</td><td>Test1Test1Test1Test1</td></tr><tr><td>rtgrgr</td><td></td>Test1tyhegergr</tr><tr><td>grgrgr</td><td></td>TestTAble</tr><tr><td>gregerg</td><td>Test1Test1Test1Test1</td></tr>
</table></div>

If  you want to select 4th row then put index number 4 in table row row[] array
$(document).ready(function(){
var row = document.getElementById("tableDiv1").rows;
row[4].scrollIntoView(false);
});

Or from any other method  

function selectRow(){
       var row = document.getElementById("tableDiv1").rows;
            row[4].scrollIntoView(false);
}