# How to get the int Length

Source: Internet
Author: User

Assume that the following method is available:

Public String fun1 (string input, int length)
{
String strreturn = input;
For (INT I = 0; I <length-input. length; I ++)
{
Strreturn = "0" + strreturn;

}
Return strreturn;

}

Call:Fun1 ("790", 4 );--> Final result:0790

Fun1 ("1234", 5 );--> Final result:01234

Assume that you have the following requirements:

If you want to convert an int-type number, for example, int temp = 790, you must convert it to "abc0790" [7 bits; ABC must have it; after ABC is removed, the remaining 4 digits are supplemented with 0 ]!

So I believe many people will make the following mistake: Get the temp Length

Int temp = 790;

Int J = 0;
For (INT I = 1; int1> 9; I ++)
{
Int1/= 10;

J + = I;

}

In this way, the length j of temp is obtained, and if is used... Else... To determine the number of zeros to add to the parameter!

Obviously, it is very troublesome! We use the above fun1, and return: Return ("ABC" + strreturn) is OK!

If I guess it is correct, many times we are misled by the surface. He needs an int-type parameter, so we only consider int, maybe not even converted to string!

Apparently "temp. Length "is not available, but string AA = temp. Tostring (), then aa. Isn't length the length of temp ???

Then, there is a textbox on another page, and the corresponding data is obtained by inputting "abc0790". What should we do?

I hope you will not be misled by the above...

The SQL statement queried in the stored procedure only requires ID, and the header before ID is not. How can this problem be removed?

String SQL = "select * from info where id =" + ID;

Controls on the page:

`No.: <asp: textbox id = "textbox1" runat = "server"> </ASP: textbox> <asp: button id = "button1" runat = "server" text = ""/>`

He only needs the following ID, so we can remove the letter "ABC", convert it to int, and then remove the first 0!

Int BB = convert. toint32 (temp. value. Replace ("ABC ",""));

BB = 790;

The final result is the same as expected!

The above items are for reference only. If you have any questions, contact us online!

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.