Sunday, February 23, 2014

concat(), replace(), and trim() Strings in Java

from java if value go(pass) database 2 rule :



1/   "+admission_no+" (If it is number that means private int admission_no)



2/   '"+admission_no+"' (If it is varchar that means private string admission_no)







*************************************************************************
<script language="javascript">
function getInputVal(td_id,numberId){
//alert(td_id);
alert("kk");
var name = td_id+numberId;
var valOne = document.getElementById(name).innerHTML;

//var valTwo = document.getElementById(numberId).innerHTML;
//var total = parseInt(valOne)+parseInt(valTwo);


alert(valOne);


}
</script>


concatanation : concatanation is add of two string result. So no need double cotation for  string variable of name.

var valOne = document.getElementById(name).innerHTML;


Not


var valOne = document.getElementById("sc").innerHTML;


*************************************************************************


Ques: What is sum and concatanation ?
sum : sum is add of two numeric value result.It is need for parseInt

************************************
************************************
*************************************
<script language="javascript">
function getInputVal(td_id,numberId){
//alert(td_id);
alert("kk");
var sc = td_id+numberId;
var valOne = document.getElementById(sc).innerHTML;
//var valTwo = document.getElementById(numberId).innerHTML;
//var total = parseInt(valOne)+parseInt(valTwo);
alert(valOne);


}
</script>




********************************************************************
Single cotation and double cotation   And no cotation
=====================================================


<td  onClick="getInputVal('record<%=i %>');"><a href="#" ><img src="images/editable.jpg" style="border:none;"/></a>

Direct value pass in function using by single or double cotation.such as-
<script language="javascript">
function getInputVal(td_id){
alert(td_id);

var val = document.getElementById(td_id).innerHTML;
alert(val);

//var val1 = document.getElementById("record1").innerHTML; and var val1 = document.getElementById('record1').innerHTML;  same


alert(val1);


}
</script>



About no cotation
==================
value pass as parameter in function using by no cotation.such as-

<td  onClick="getInputVal('record<%=i %>');"><a href="#" ><img src="images/editable.jpg" style="border:none;"/></a>

Direct value pass in function using by single or double cotation.such as-
<script language="javascript">
function getInputVal(td_id){
alert(td_id);

var val = document.getElementById(td_id).innerHTML;
alert(val);



}
</script>


*********************************************************
<jsp:include page="adminInclude/menu/adminLeftMenu.jsp"></jsp:include>


save = insert query
edit = update query


===============================================
kaniz : subject : oracle data type
..................................

http://docs.oracle.com/cd/B14117_01/server.101/b10759/sql_elements003.htm


kaniz : subject : java sms send
..................................
http://www.ipipi.com/help/send_text_message_using_java.htm
===============================================

================================================
Java model class a Private int COUNTRY_ID means only indicate intiger vaue. (Here int is primitive type data type)

Java model class a Private Intiger COUNTRY_ID means it indicates intiger or string value.

=================================================
######################################################################
######################################################################

http://www.java-samples.com/showtutorial.php?tutorialid=339

concat()
You can concatenate two strings using concat(), shown here:
String concat(String str)
This method creates a new object that contains the invoking string with the contents of str appended to the end. concat( ) performs the same function as +. For example,
String s1 = "one"; 
String s2 = s1.concat("two");

puts the string "onetwo" into s2. It generates the same result as the following sequence:
String s1 = "one"; 
String s2 = s1 + "two";

replace()
The replace( ) method replaces all occurrences of one character in the invoking string with another character. It has the following general form:
String replace(char original, char replacement)
Here, original specifies the character to be replaced by the character specified by replacement. The resulting string is returned. For example,
String s = "Hello".replace('l', 'w');
puts the string "Hewwo" into s.
trim()
The trim( ) method returns a copy of the invoking string from which any leading and trailing whitespace has been removed. It has this general form:
String trim( )
Here is an example:
String s = " Hello World ".trim();
This puts the string "Hello World" into s.
The trim( ) method is quite useful when you process user commands. For example, the following program prompts the user for the name of a state and then displays that state's capital. It uses trim( )to remove any leading or trailing whitespace that may have inadvertently been entered by the user.
// Using trim() to process commands. 
import java.io.*; 
class UseTrim { 
public static void main(String args[]) 
throws IOException 
{ 
// create a BufferedReader using System.in 
BufferedReader br = new 
BufferedReader(new InputStreamReader(System.in)); 
String str; 
System.out.println("Enter 'stop' to quit."); 
System.out.println("Enter State: "); 
do { 
str = br.readLine(); 
str = str.trim(); // remove whitespace 
if(str.equals("Illinois")) 
System.out.println("Capital is Springfield."); 
else if(str.equals("Missouri")) 
System.out.println("Capital is Jefferson City."); 
else if(str.equals("California")) 
System.out.println("Capital is Sacramento."); 
else if(str.equals("Washington")) 
System.out.println("Capital is Olympia."); 
// ... 
} while(!str.equals("stop")); 
} 
}

No comments:

Post a Comment