Advertisement
NarekNavoyan

Untitled

Aug 25th, 2023
1,542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.59 KB | None | 0 0
  1. package edu.example
  2.  
  3. fun main() {
  4.     val input = "test:value,password:secret,something:value"
  5.     val passwordKey = "password:"
  6.  
  7.     var keyCurrentIndex = 0
  8.     val result = CharArray(input.length)
  9.     for (charIndex in input.indices) {
  10.         if (keyCurrentIndex > 0 && input[charIndex] == ',') {
  11.             keyCurrentIndex = -1
  12.         }
  13.         else if (keyCurrentIndex == passwordKey.length) {
  14.             result[charIndex] = '*'
  15.             continue
  16.         }
  17.         else if (keyCurrentIndex != -1 && input[charIndex] == passwordKey[keyCurrentIndex]) {
  18.             keyCurrentIndex++
  19.         }
  20.  
  21.         result[charIndex] = input[charIndex]
  22.     }
  23.  
  24.     println(result)
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement