濮阳杆衣贸易有限公司

主頁 > 知識庫 > 用shell腳本和c語言將大寫字母轉(zhuǎn)成小寫的代碼

用shell腳本和c語言將大寫字母轉(zhuǎn)成小寫的代碼

熱門標簽:打電話機器人接我是他的秘書 百度地圖標注錯了有責任嗎 揭陽智能電話機器人推薦 地圖標注員都是年輕人 河南信譽好的不封卡電話外呼系統(tǒng) 華鋒e路航港口地圖標注 如果做線上地圖標注 江蘇云電銷機器人公司 客服外呼系統(tǒng)怎么樣

復制代碼 代碼如下:

#!/bin/bash
#name: upper_to_lower.sh
#the function is trun uper to lower
#like ABCd to abcd

haveuppernumber()
{
    #test if the string have upper number
    str="$(echo $1 | tr '[:upper:]' '[:lower:]')"
    if [ "$str" != $1 ] ; then #get some problem
        echo "[#have upper number,and i well trun them to lower:#]"
        return 1 #have upper number
    else
        return 0 #no upper number
    fi
}

if [ $# -ne 1 ] ; then
    echo "Usage: $0 string>" >2
    exit 1
fi

if ! haveuppernumber $1 ; then #when if is 0 it run?
#if [ 0 ] ; then #in shell true return 0 ,false return 1
    echo $1 | tr '[:upper:]' '[:lower:]' #it can turn the UPPER number to lower
#    echo $1 | tr '[:lower:]' '[:upper:]' #it can turn the lower number to UPPER
else
    echo "[#no upper number:#]"
    echo $1
fi

exit 0

功能說明:當輸入”./upper_to_lower.sh AaBbCcdd“時會先判斷輸入格式是否正確,然后判斷字符串中是否有大寫字母如果有顯示"[#have upper number,and i well trun them to lower:#]"和轉(zhuǎn)換成小寫字母后的字符串;如果沒有大寫字母顯示"[#no upper number:#]"和小寫字符串。

然后又試著用c語言實現(xiàn)相同的功能,如下:

復制代碼 代碼如下:

#includestdio.h>
#includestdlib.h>

int haveuppernumber(char *p)
{
    char*q=p;

    for(;*q!='\0';q++)
    {
        if(*q>='A'*q='Z')
        {
            printf("[#have upper number and i will turn them to lower #]\n");
            return 1;
        }
    }
    printf("[#no upper number#]\n");
    return 0;
}
void turntolower(char *p)
{
    for(;*p != '\0';p++)
    {
        if(*p>='A' *p='Z')
        {
            *p+=' ';
        }
    }
}

int main(int argc , char *argv[])
{
    char *p;
    p=argv[1];

    if(argc != 2)
    {
        printf("Usage : %s string>\n",argv[0]);
        exit(-1);
    }
    if(haveuppernumber(p))
    {
        turntolower(p);
        printf("%s\n",argv[1]);
    }
    else
    {
        printf("%s\n",argv[1]);
    }
    return 0;
}


您可能感興趣的文章:
  • C語言中對字母進行大小寫轉(zhuǎn)換的簡單方法
  • C語言實現(xiàn)字母大小寫轉(zhuǎn)換的方法
  • c語言將字符串中的小寫字母轉(zhuǎn)換成大寫字母

標簽:巴彥淖爾 馬鞍山 許昌 婁底 淘寶邀評 赤峰 金昌 邵陽

巨人網(wǎng)絡(luò)通訊聲明:本文標題《用shell腳本和c語言將大寫字母轉(zhuǎn)成小寫的代碼》,本文關(guān)鍵詞  用,shell,腳本,和,語言,將,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《用shell腳本和c語言將大寫字母轉(zhuǎn)成小寫的代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于用shell腳本和c語言將大寫字母轉(zhuǎn)成小寫的代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    涟水县| 南丰县| 浮梁县| 弋阳县| 金华市| 凤台县| 辽源市| 柳林县| 淳化县| 秭归县| 抚顺市| 眉山市| 来安县| 镇巴县| 达拉特旗| 龙山县| 海晏县| 泰兴市| 磐安县| 福泉市| 常德市| 乃东县| 连平县| 大邑县| 来安县| 井冈山市| 万载县| 文化| 工布江达县| 姜堰市| 商都县| 周宁县| 阿尔山市| 晋宁县| 南安市| 三河市| 安阳市| 福贡县| 芮城县| 确山县| 米易县|