3/23/2022

Powershell 的比較運算子

 比較運算子有分字串及數字的比較。字串又分為限制大小寫及不限制大小寫的比較。

若是要比較大小寫時,需在運算子前面加上c字元,如-cle。
    運算子
    說明
    範例
    結果
    -le
    小於或等於
    (字串不限大小寫)
    10 –le 10
    9 –le 10
    “A” –le “a”
    “B” –le “A”
    True
    True
    True
    False
    -lt
    小於
    (字串不限大小寫)
    10 –lt 10
    9 –lt 10
    “A” –lt “a”
    “A” –lt “B”
    False
    True
    False
    True
    -ge
    大於或等於
    (字串不限大小寫)
    10 –ge 10
    11 –ge 10
    “A” –ge “a”
    “A” –ge “B”
    True
    True
    True
    False
    -gt
    大於
    (字串不限大小寫)
    10 –gt 10
    11 –gt 10
    “A” –gt “a”
    “B” –gt “A”
    False
    True
    False
    True
    -eq
    相等
    (字串不限大小寫)
    10 –eq 10
    9 –eq 10
    “A” –eq “a”
    “A” –eq “b”
    True
    False
    True
    False
    -ne
    不相等
    (字串不限大小寫)
    10 –ne 10
    9 –ne 10
    “A” –ne “a”
    “A” –ne “b”
    False
    True
    False
    True
    -like
    相似
    (字串可用*和?替代,並不限大小寫)
    “ABC” –like “a*”
    “ABC” –like “a??”
    “ABC” –like “a?”
    True
    True
    False
    -notlike
    不相似
    (字串可用*和?替代,並不限大小寫)
    “ABC” –notlike “a*”
    “ABC” –notlike “a??”
    “ABC” –notlike “a?”
    False
    False
    True
    -match
    符合
    (字串不限大小寫,並不限大小寫)
    “ABC” –match “A”
    “ABC” –match “a”
    “ABC” –match “[AE]”
    “ABC” –match “AE”
    True
    True
    True
    False
    -notmatch
    不符合
    (字串不限大小寫,並不限大小寫)
    “ABC” –notmatch “A”
    “ABC” –notmatch “a”
    “ABC” –notmatch “[AE]”
    “ABC” –notmatch “AE”
    False
    False
    False
    True
    -contains
    包含
    (運算子的左邊含有右邊的值,並不限大小寫)
    “A”,”B”,”C” –contains “A”
    “a”,”b”,”c” –contains “A”
    “c”,”d”,”e” –contains “A”
    True
    True
    False
    -notcontains
    不包含
    (運算子的左邊含有右邊的值,並不限大小寫)
    “A”,”B”,”C” –contains “A”
    “a”,”b”,”c” –contains “A”
    “c”,”d”,”e” –contains “A”
    False
    False
    True

    Powershell的型別運算子

     

    • -is 用於判別是不是某種型別

    • PS C:\> 12345 -is [int]
      True
      PS C:\> 12345 -is [double]
      False

    • -isnot 用於判別是不是非某種型別

    • PS C:\> 12345 -isnot [int]
      False
      PS C:\> 12345 -isnot [double]
      True

    • -as 將物件轉成指定的型別

    • PS C:\> $StrA = 12345
      PS C:\> $StrA.GetType().Name
      Int32

      PS C:\> $StrA = 12345 -as [string]
      PS C:\> $StrA.GetType().Name
      String

    設定 Eclipse IDE 的 Java 基本環境

     

    • 設定encoding
    開啟【Preferences】的【General】\【Workspace】。選擇 Text file encoding 的Other,並改為 UTF-8。 



















    • 增加輸入字元的判斷

    開啟【Preferences】的【Java】\【Editor】\【Content Assist】。在Auto Activation的欄位Auto activation triggers for Java輸入字元 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.("




















    • 用Eclipse Marketplace更換 Theme

    Marketplace 有很多 Theme 可以選擇。個人推薦 Darkest Dark Theme with DevStyle。


      1. 在Find 輸入 Darkest Dark Theme with DevStyle。並按下Install 。
      2. 全選後進入安裝程序
      3. 重新開啟Eclipse後會有提問視窗詢問希望更換成屬意的Theme



    • 將Google Java Code Style 加入Eclipse 環境
    1. GitHub 複製下圖xml 內文到 Notepad 。並在本機儲存檔案設定為 eclipse-java-google-style.xml
    2. 開啟【Preferences】的【Java】\【Code Style】\【Formatter】。按下 Import 按鈕,匯入eclipse-java-google-style.xml
    3. 選擇Google Style


    7/24/2016

    將資料以Unicode 方式存入SQL Server資料庫


    作法是在字串前方加上N的字元。
    •  Insert
    • Insert into material_code ( code, name ) values ( 'A0001', N'塑膠' )

    • Update 
    • Update material_code set name = ( N'木材' ) where code = 'A0001'
       
    參考資料 https://msdn.microsoft.com/en-us/library/ms177523.aspx

    1/05/2014

    【人生一定要交的六個朋友】



    【人生一定要交的六個朋友】
    沙子是廢物,水泥也是廢物,但他們混在一起是混凝土,就是精品;
    大米是精品,汽油也是精品,但他們混在一起就是廢物。
    所以,是精品還是廢物不重要。
    跟誰混,很重要!
    中國國家主席『習近平』說:
    朋友不是亂交的,每天在一起喝酒的,不一定是真朋友;每天在一起混的,也不一定是永遠的朋友。
    人生要交的六類朋友:
    1、交一個【欣賞你】的朋友:即便在你窮困潦倒的時候也會安慰你、幫助你。
    2、交一個有【正能量】的朋友:在你情緒低落的時候陪伴你、鼓勵你。
    3、交一個【爲你領路】的朋友:自願做你的墊腳石,帶你走過泥濘、撥開迷霧。
    4、交一個【肯指點你】的朋友:願意花時間提點你。
    5,交一個【願意和你吵架】的朋友:沒事願意嘮叨你、監督你,讓你時刻發現自己的不足。
    6、交一位【不放棄】你的朋友:經常會傳一些笑話、正能量文章給你的朋友。
    【財富不是永遠的朋友,朋友卻是永遠的財富】

    8/28/2013

    常用字根

    最近閱讀文法書,將常用的字根做了一些詞性分類



    詞性
    字尾
    字彙
    名詞
    -ance
    -ancy
    -ence
    -ation
    -dom
    -ism
    -ist
    -ment
    -ness
    -ship
    -or
    -er
    -ion
    performance
    tenancy
    affluence
    mobilization
    freedom
    capitalism
    specialist
    treatment
    illness
    relationship
    actor
    reader
    attraction
    動詞
    -en
    -ify
    -ize
    darken
    simplify
    regularize
    形容詞
    -able
    -ible
    -al
    -ful
    -ish
    -ive
    -ly
    drinkable
    legible
    national
    helpful
    childish
    attractive
    friendly
    副詞
    -ly
    -ward
    -wise
    friendly
    backward
    lengthwise



    其他字根的說明可以參考Learn That word 網站看看。

    8/13/2013

    CISCO 指令 : 利用 SSH 遠端登入系統

    Switch0:192.168.1.20/24
    PC0 :192.168.1.10/24 
    假設有一組Switch因為資訊安全考量,在PC端要採用SSH Client連到Switch。


    為了建立SSH的連線方式,切記要先把hostname、Domain Name設定好。
    這時用內建指令產生RSA 的公私鑰,作為SSH Client端使用。


    操作指令如下:

    Switch>enable
    Switch#configure terminal
    Enter configuration commands, one per line.  End with CNTL/Z.
    Switch(config)#enable secret first
    Switch(config)#line vty 0 15
    Switch(config-line)#login local
    Switch(config-line)#transport input ssh
    Switch(config-line)#exit
    Switch(config)#username usr1 password usr123
    Switch(config)#ip domain-name test.com
    Switch(config)#hostname switch0
    Switch>enable
    Switch#configure terminal
    Enter configuration commands, one per line.  End with CNTL/Z.
    Switch(config)#enable secret first
    Switch(config)#interface vlan 1
    switch0(config)#exit

    switch0(config)#crypto key generate rsa
    The name for the keys will be: switch0.test.com
    Choose the size of the key modulus in the range of 360 to 2048 for your
      General Purpose Keys. Choosing a key modulus greater than 512 may take
      a few minutes.

    How many bits in the modulus [512]:
    % Generating 512 bit RSA keys, keys will be non-exportable...[OK]

    switch0(config)#



    程序說明:
    1. login local 是提供可以用於驗證user name及密碼的通訊環境。
    2. transport input ssh 是指定ssh 為允許的通訊方式。
    3. username / password 設定登入帳號密碼
    4. ip domain-name 設定domain name
    5. hostname 設定 host name
    6. enable secret 設定登入Privileged EXEC Mode
    7.  crypto key generate rsa 產生RSA 的公私鑰
    8. 依據實際需要當系統出現 "How many bits in the modulus [512]:"時,可以採用預設512bit及1024bit以上的位元數產生符合需要的RSA Keys.


    動作完成後,利用crypto key mypubkey rsa 指令,查詢RSA Keys的資訊。

    switch0#show crypto key mypubkey rsa
    % Key pair was generated at: 0:24:14 UTC ?? 1 1993
    Key name: switch0.test.com
     Storage Device: not specified
     Usage: General Purpose Key
     Key is not exportable.
     Key Data:
     00002d61  00000a53  00006eab  00002249  00002ef4  00007612  00006e46  00001e2e
     0000015a  000009dd  00007a2e  00006bdd  00006e5c  000041e9  00005113  0000754f
     000005de  00004519  00003a9e  00006e9d  00004a65  00006f72  00003810  5416
    % Key pair was generated at: 0:24:14 UTC ?? 1 1993
    Key name: switch0.test.com.server
    Temporary key
     Usage: Encryption Key
     Key is not exportable.
     Key Data:
     000006d6  000060cf  00002826  00000e8e  00003181  000063d6  0000623f  000031f8
     0000005d  0000412a  00000cc0  00000a38  00001295  000052e2  000032b8  00006a32
     00005344  00006c3b  00005cc0  00007127  0000797d  00006989  00003126  3a41
    switch0#



    下圖是利用PC0 藉由 SSH Client登入Switch0。usr1 為登入帳號,並會要求輸入password。