노무현 전 대통령 서거 추모글 남기기

http://www.androidpub.com/80310   -회색

Posted by Kelly Cook
,

http://www.androidpub.com/511504#19


Posted by Kelly Cook
,

1. String 클래스의 메서드
  • 문자열 비교 (대소문자 구분)
str1.equals(str2);    // 같으면 true 리턴
  • 문자열 비교 (대소문자 구문 안함)
str1.equalsIgnoreCase(str2) ;   // 같으면 true 리턴
 
 
※ str1 과 str2 는 Object 이므로 str1,str2 라는 변수에는 실제 데이터가 들어있는 메모리주소의
    해시값이 들어 있을 뿐이므로 str1 == str2  이라고 값을 비교하는 것이 무의미 하다.
 
    문자열 억제(intern()메서드)를 통해 str1 == str2 라고 비교하는 방법이 가능하기는 하지만 거의 쓸일이 없을거라고 본다.
  • intern() 메서드

str1 객체에 의해 참조되고 있는 문자열과 같은 String 객체가 존재하는지를 검사하여 존재하면 현재의 객체는 버려지고 str1은 이미 존재하고 있는 값이 같은 문자열 객체를 참조하게 된다.

 

같은 참조값을 가지므로 == 연산자로 비교가 가능하게 되는 것이다.

 

ex)

String str1 = "같은 문자열이지만 참조값은 다르다.";
String str2 = "같은 문자열이지만 참조값은 다르다.";
  
str2.intern();
  
if(str1 == str2){
   logger.info("같아요~~~~");
}

 

result)

INFO  com.bws.newBoardDev.controller.ReportTestCtl.reportViewTest(ReportTestCtl.java:77) - 같아요~~~~

 

  • 문자열의 시작 검사

str1.startsWith(prefix)    //str1 이 String prefix 로 시작하면 true 리턴

  • 문자열의 끝을 검사

str1.endsWith(suffix)    //str1 이 String suffix 로 끝나면 true 리턴

  • 문자열 비교

Compares two strings lexicographically.

The comparison is based on the Unicode value of each character in the strings

(두개의 String 객체를 사전적으로 비교한다.각 String 객체의 각 문자의 유니코드 값을 비교한결과 리턴)

 

str1.compareTo(anotherString)

 

  • 문자 추출

Returns the char value at the specified index. An index ranges from 0 to length() - 1

(문자열의 index 0부터 length()-1 사이의 지정한 index의 문자를 리턴한다.

 

str1.charAt(index);

  • 문자열 길이

Returns the length of this string. The length is equal to the number of Unicode code units in the string

(유니코드 단위의 문자열 길이를 리턴한다.) 

 

str1.length()

  • 문자열 검색

Returns the index within this string of the first occurrence of the specified substring

(특정 문자열이 처음 발생한 index를 리턴한다.)

 

str1.indexOf(특정문자열)

 

Returns the index within this string of the rightmost occurrence of the specified substring

(특정 문자열 발생한 맨 오른쪽의 index를 리턴한다)

 

str1.lastIndexOf(특정문자열)

※ 특정문자열을 못찾으면 -1 을 리턴한다.

 

  • 부분 문자열 추출

Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string

(beginIndex 의 문자 부터 문자열의 끝까지에 해당하는 새로운 부분 문자열을 리턴한다.)

 

str1.substring(beginIndex) 

Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1

(beginIndex 의 문자 부터 endIndex-1 의 문자까지의 문자열을 새로운 부분 문자열로 리턴한다.)


str1.substring(beginIndex, endIndex)

  • 문자열 수정

str.replace('oldCharacter', 'newCharacter')

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.  

 

ex)

String str = "aaa";
String newStr = str.replace('a', 'b');
  
System.out.println(str);                // aaa 출력
System.out.println(newStr);          // bbb 출력

 

str.replaceAll(String regex , String replacement)

Replaces each substring of this string that matches the given regular expression with the given replacement.

ex)

String str2 = str.replaceAll("[abc]","c");

String str2 = str.replaceAll("a","c");

 

  • 문자열의 처음과 끝의 공백제거

str.trim()

Returns a copy of the string, with leading and trailing whitespace omitted.

 

  • String 객체에서 char 배열 리턴

str.toCharArray();

Converts this string to a new character array.

 

str.getChars(srcBegin, srcEnd, dst, dstBegin)

Copies characters from this string into the destination character array.

The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1


첫번째 인자 : 추출할 첫번째 인덱스

두번째 인자 : 추출할 마지막 문자의 다음 인덱스(srcEnd -1 까지 카피된다)

세번재 인자 : 추출할 문자를 저장할 배열의 이름

네번째 인자 : 첫번재 문자를 저장할 인덱스 


  • String 객체에서 byte 배열 리턴

str.getBytes();

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

(문자열을 byte[] 로 추출함 8bit 문자로 변환되며 상위 바이트들은 버려짐


str.getBytes(charset);

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.


str.getBytes(charsetName)

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.

 

str.getBytes(srcBegin, srcEnd, dst, dstBegin) (비추천)

Copies characters from this string into the destination byte array. Each byte receives the 8 low-order bits of the corresponding character. The eight high-order bits of each character are not copied and do not participate in the transfer in any way

 

The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters, converted to bytes, are copied into the subarray of dst starting at index dstBegin and ending at index

첫번째 인자 : 추출할 첫번째 인덱스

두번째 인자 : 추출할 마지막 문자의 다음 인덱스(srcEnd -1 까지 카피된다)

세번재 인자 : 추출할 문자를 저장할 배열의 이름

네번째 인자 : 첫번재 문자를 저장할 인덱스 

 


  • 문자배열 (char[])에서 String 객체 생성

String.copyValueOf(data, offset, count)

Returns a String that represents the character sequence in the array specified. 


data - the character array.(배열의 이름)
offset - initial offset of the subarray.(추출할 배열의 첫번째 문자 인덱스)
count - length of the subarray.(추출할 문자의 갯수)

인자가 없으면 전체 배열을 String으로 변환
Posted by Kelly Cook
,
remount 한다.
>adb remount

안드로이드에 있는 host 파일을 받는다.
>adb pull /system/etc/hosts D:\TDPlatform\android_home\backup\

hosts 파일 수정한다.
---------------------------------------
기본적으로 로컬만 등록되어 있음.
127.0.0.1      localhost
---------------------------------------

host 파일을 넣는다.
>adb push D:\TDPlatform\android_home\work\hosts /system/etc/


hosts 파일 수정 확인해보기

>adb -e shell
#cat /system/etc/hosts
Posted by Kelly Cook
,

Nine-Patch Stretchable Image

Android supports a stretchable bitmap image. This is a PNG image in which you define stretchable sections that Android will resize to fit the object at display time to accommodate variable sized sections, such as text strings. You typically assign this resource to the View's background. An example use of a stretchable image is the button backgrounds that Android uses; buttons must stretch to accommodate strings of various lengths.

A NinePatch drawing is a standard PNG image that includes a 1 pixel wide border. This border is used to define the stretchable and static areas of the screen. You indicate a stretchable section by drawing one or more 1 pixel wide black lines in the left or top part of this border. You can have as many stretchable sections as you want. The relative size of the stretchable sections stays the same, so the largest sections always remain the largest.

You can also define an optional drawable section of the image (effectively, the padding lines) by drawing a line on the right and bottom lines. If you do not draw these lines, the first top and left lines will be used.

If a View object sets this graphic as a background and then specifies the View object's text, it will stretch itself so that all the text fits inside the area designated by the right and bottom lines (if included, the first top and left lines otherwise). If the padding lines are not included, Android uses the left and top lines to define the writeable area.

Here is a sample NinePatch file used to define a button.

Raw ninepatch file showing the definition lines

This ninepatch uses one single stretchable area, and it also defines a drawable area.

Here are two buttons based on this graphic. Notice how the width and height of the button varies with the text, and the background image stretches to accommodate it.

Two buttons based on the NinePatch button background

Source file format: PNG -- one resource per file

Resource source file location: res/drawable/somename.9.png (must end in .9.png)

Compiled resource datatype: Resource pointer to a NinePatchDrawable

Resource reference name:

  • Java R.drawable.somefile
  • XML @[package:]drawable.somefile

Example Code Use

Example XML code

Note that the width and height are set to "wrap_content" to make the button fit neatly around the text.

<Button id="@+id/big"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:text="Tiny"
        android:textSize="8sp"
        android:background="@drawable/my_button_background"/>
      
<Button id="@+id/big"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:text="Biiiiiiig text!"
        android:textSize="30sp"
        android:background="@drawable/my_button_background"/>

Posted by Kelly Cook
,