Light Blue Pointer
본문 바로가기
개발일지

2023-10-30 Today I Learned

by 개발바닥곰발바닥!!! 2023. 10. 30.

오늘 개발한 것

https://greedydeveloper.tistory.com/87

 

[내일배움캠프][팀프로젝트]키오스크 개발일지

https://github.com/minisundev/Kiosk GitHub - minisundev/Kiosk: Kiosk program for a burger place Kiosk program for a burger place. Contribute to minisundev/Kiosk development by creating an account on GitHub. github.com 오늘의 목표 오늘의 목표는

greedydeveloper.tistory.com

 

 

오늘 푼 문제

https://greedydeveloper.tistory.com/90

 

[프로그래머스]대소문자 바꿔서 출력하기

문제 주소 https://school.programmers.co.kr/learn/courses/30/lessons/181949 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁

greedydeveloper.tistory.com

문제 풀면서 배운것

⭐Java에서 대소문자 바꿔서 출력하는 방법

String string = "aBcDeF"
string = string.toUpperCase();//ABCDEF
string = string.toLowerCase();//abcdef

⭐equalsIgnoreCase()

→ .equals()랑 똑같은 방법으로 사용, 대소문자는 무시하고 비교해준다

String str1 = "ABC"
String str2 = "abd"
str1.equalsIgnoreCase(str2)//true

예외처리 강의 들을때 matches본거 기억남

⭐String match()

String이 특정 패턴의 문자열을 포함하는지 확인할 수 있음

문자열에 정규표현식(regex)이 일치하는지를 boolean으로 리턴

String str = "my java test";

        //정확히 일치해야 true
        System.out.println( str.matches("java") );  // false
        System.out.println( str.matches("my java Test") );  // false (대/소문자 역시 구분한다.)
        System.out.println( str.matches("my java test") );  // true

        //정규표현식 사용-> 패턴이 맞으면 true
        System.out.println( str.matches(".*java.*") );  // true
        System.out.println( str.matches("(.*)test") );  // true

⭐Java Regular Expressions(Regex,정규표현식)

  • Pattern Class - Defines a pattern (to be used in a search)
  • Matcher Class - Used to search for the pattern
  • PatternSyntaxException Class - Indicates syntax error in a regular expression pattern
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) {
    Pattern pattern = Pattern.compile("min", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher("mintchoco");
    boolean matchFound = matcher.find();
    if(matchFound) {
      System.out.println("Match found");
    } else {
      System.out.println("Match not found");
    }
  }
}
// Outputs Match found

Match found

 

1. Pattern.compile() 메서드로 패턴이 만들어진다.

첫번째 parameter : 어떤 패턴이 찾아지는지 지정(필수)

두번째 parameter : case-insensitive 지정(선택)

 

2. matcher() 메서드가 문자열 안에서 패턴을 찾고 결과값을 담 Matcher object를 리턴한다

3. find() 메서드가 패턴이 발견되면 true를 발견되지 않았으면 false를 반환한다

Flags : flags in the compile() method

  • Pattern.CASE_INSENSITIVE - The case of letters will be ignored when performing a search.
  • Pattern.LITERAL - Special characters in the pattern will not have any special meaning and will be treated as ordinary characters when performing a search.
  • Pattern.UNICODE_CASE - Use it together with the CASE_INSENSITIVE flag to also ignore the case of letters outside of the English alphabet

Pattern.compile()의 첫번째 parameter

⭐Regular Expression Patterns

[abc] Find one character from the options between the brackets

[^abc] Find one character NOT between the brackets
[0-9] Find one character from the range 0 to 9

⭐Metacharacters : characters with a special meaning

| | | Find a match for any one of the patterns separated by | as in: cat|dog|fish | | --- | --- | | . | Find just one instance of any character | | ^ | Finds a match as the beginning of a string as in: ^Hello | | $ | Finds a match at the end of the string as in: World$ | | \d | Find a digit | | \s | Find a whitespace character | | \b | Find a match at the beginning of a word like this: \bWORD, or at the end of a word like this: WORD\b | | \uxxxx | Find the Unicode character specified by the hexadecimal number xxxx |

⭐Quantifiers : Quantifiers define quantities

n+ Matches any string that contains at least one n

n* Matches any string that contains zero or more occurrences of n
n? Matches any string that contains zero or one occurrences of n
n{x} Matches any string that contains a sequence of X n's
n{x,y} Matches any string that contains a sequence of X to Y n's
n{x,} Matches any string that contains a sequence of at least X n's

⭐Java String to Char array

// define a string
String vowels = "aeiou";

// create an array of characters 
char[] vowelArray = vowels.toCharArray();

// print vowelArray
System.out.println(Arrays.toString(vowelArray));

 

'개발일지' 카테고리의 다른 글

2023-11-01, Today I Learned  (1) 2023.11.01
2023-10-31, Today I Learned  (0) 2023.10.31
2023-10-25, Today I Learned  (0) 2023.10.27
2023-10-23 Today I learned  (0) 2023.10.23
2023-10-20 Today I Learned  (1) 2023.10.20