PowerBuilder Remove Vietnamese Characters
If you need to remove Vietnamese characters when the user enters without accents in Vietnamese, this is the solution for you
Source Code
f_global_replace from function_object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | global type f_global_replace from function_object end type forward prototypes global function string f_global_replace (string as_source, string as_old, string as_new, boolean ab_ignorecase) end prototypes global function string f_global_replace (string as_source, string as_old, string as_new, boolean ab_ignorecase);///////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function Name : f_global_replace // Argument Name : as_source, Arg Type : String, Pass By : Value // as_old, Arg Type : String, Pass By : Value // as_new, Arg Type : String, Pass By : Value // ab_ignorecase, Arg Type : Boolean, Pass By : Value // Return Type : String /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Replace all occurrences of one string inside another with // a new string. // // Arguments: // as_Source The string being searched. // as_Old The old string being replaced. // as_New The new string. // ab_IgnoreCase A boolean stating to ignore case sensitivity. // // Returns: string // as_Source with all occurrences of as_Old replaced with as_New. // If any argument's value is NULL, function returns NULL. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// Long ll_Start Long ll_OldLen Long ll_NewLen String ls_Source //Check parameters If IsNull(as_source) or IsNull(as_old) or IsNull(as_new) or IsNull(ab_ignorecase) Then string ls_null SetNull(ls_null) Return ls_null End If //Get the string lenghts ll_OldLen = Len(as_Old) ll_NewLen = Len(as_New) //Should function respect case. If ab_ignorecase Then as_old = Lower(as_old) ls_source = Lower(as_source) Else ls_source = as_source End If //Search for the first occurrence of as_Old ll_Start = Pos(ls_Source, as_Old) Do While ll_Start > 0 // replace as_Old with as_New as_Source = Replace(as_Source, ll_Start, ll_OldLen, as_New) //Should function respect case. If ab_ignorecase Then ls_source = Lower(as_source) Else ls_source = as_source End If // find the next occurrence of as_Old ll_Start = Pos(ls_Source, as_Old, (ll_Start + ll_NewLen)) Loop Return as_Source end function |
f_khongdau from function_object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | global type f_khongdau from function_object end type forward prototypes global function string f_khongdau (string as_string) end prototypes global function string f_khongdau (string as_string);//==================================================================== // Function: f_khongdau() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value string as_string //-------------------------------------------------------------------- // Returns: string //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/12 //-------------------------------------------------------------------- // Usage: f_khongdau ( string as_string ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_a[17] = {'à','á','ạ','ả','ã','â','ầ','ấ','ậ','ẩ','ẫ','ă','ằ','ắ','ặ','ẳ','ẵ'} String ls_e[11] = {'è','é','ẹ','ẻ','ẽ','ê','ề','ế','ệ','ể','ễ'} String ls_i[5] = {'ì','í','ị','ỉ','ĩ'} String ls_o[17] = {'ò','ó','ọ','ỏ','õ','ô','ồ','ố','ộ','ổ','ỗ','ơ','ờ','ớ','ợ','ở','ỡ'} String ls_u[11] = {'ù','ú','ụ','ủ','ũ','ư','ừ','ứ','ự','ử','ữ'} String ls_y[5] = {'ỳ','ý','ỵ','ỷ','ỹ'} String ls_d[1] = {'đ'} String ls_khongdau ls_khongdau = as_string Int i For i = 1 To UpperBound(ls_a) ls_khongdau = f_global_replace(ls_khongdau,ls_a[i], 'a',True ) Next For i = 1 To UpperBound(ls_e) ls_khongdau = f_global_replace(ls_khongdau,ls_e[i], 'e',True ) Next For i = 1 To UpperBound(ls_i) ls_khongdau = f_global_replace(ls_khongdau,ls_i[i], 'i',True ) Next For i = 1 To UpperBound(ls_o) ls_khongdau = f_global_replace(ls_khongdau,ls_o[i], 'o',True ) Next For i = 1 To UpperBound(ls_u) ls_khongdau = f_global_replace(ls_khongdau,ls_u[i], 'u',True ) Next For i = 1 To UpperBound(ls_y) ls_khongdau = f_global_replace(ls_khongdau,ls_y[i], 'y',True ) Next For i = 1 To UpperBound(ls_d) ls_khongdau = f_global_replace(ls_khongdau,ls_d[i], 'd',True ) Next //ls_khongdau = f_global_replace(ls_khongdau,' ', '-',True ) //ls_khongdau = f_global_replace(ls_khongdau,'--', '',True ) //ls_khongdau = f_global_replace(ls_khongdau,'', '',True ) Return ls_khongdau end function |
Find Projects On Github click here
Good Luck!