ampersand

ampersand

Postby VictorCasajuana » Tue Jun 13, 2023 9:35 am

Hola.

Tengo una duda, cuando el string que se incluye en un Say contiene un ampersand &, no lo muestra correctamente ya que el say procesa el & como un shortcut del teclado, para mostrar el & hay que incluirlo 2 veces:
Esto no se muestra bien:
"hola & adios"
Esto se muestra bien:
"hola && adios"

Hay alguna función de FW que haga un "sanitize" de los strings para que se pueda mostrar correctamente? es por no hacerla y reinventar la rueda.

Salud!
--------
¿ Y porque no ?
¿ And why not ?
User avatar
VictorCasajuana
 
Posts: 268
Joined: Wed Mar 28, 2018 4:38 pm
Location: Vinaròs

Re: ampersand

Postby karinha » Tue Jun 13, 2023 2:05 pm

Holá, small sample? Pequeño ejemplo? Gracias. Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: ampersand

Postby VictorCasajuana » Tue Jun 13, 2023 6:33 pm

the sample:
Code: Select all  Expand view  RUN

#include 'fivewin.ch'

Function Main()

    DEFINE DIALOG oDlg TITLE "Test"

    @ 1,1 SAY "Hello & Bye" OF oDlg
    @ 2,1 SAY "Hello && Bye" OF oDlg

    ACTIVATE DIALOG oDlg CENTERED

Return Nil
 


the result:
Image
--------
¿ Y porque no ?
¿ And why not ?
User avatar
VictorCasajuana
 
Posts: 268
Joined: Wed Mar 28, 2018 4:38 pm
Location: Vinaròs

Re: ampersand

Postby karinha » Tue Jun 13, 2023 9:03 pm

Hola Victor. Mira se ayuda:

Code: Select all  Expand view  RUN

#include 'fivewin.ch'
#include "WColors.ch"

STATIC lWhen := .F.

Function Main()

    LOCAL oDlg, oFnt, oFont, oBot01

    DEFINE FONT oFnt  NAME "Ms Sans Serif"  SIZE 00, -12 BOLD
    DEFINE FONT oFont NAME "Ms Sans Serif"  SIZE 00, -16 BOLD

    DEFINE DIALOG oDlg TITLE "FiveWin: Victor Casajuana & And && Wow()" ;
       SIZE 400, 320 FONT oFont COLOR CLR_BLACK, CLR_WHITE TRANSPARENT

    oDlg:lHelpIcon := .F.

    @ 1,1 SAY "Hello & Bye Incorrect" OF oDlg UPDATE SIZE 190, 12 ;
       COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 2,1 SAY "Hello &Bye correct ALT+B" OF oDlg UPDATE SIZE 190, 12 ;
       COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 3,1 SAY "Hello && Bye es una Empresa-Correct" OF oDlg UPDATE ;
        SIZE 190, 12 COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 4,1 SAY "Hello &&Bye incorrect no es una Empresa" OF oDlg UPDATE ;
        SIZE 190, 12 COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 5,1 SAY "&Y porque no? ALT+Y" OF oDlg UPDATE SIZE 190, 12 ;
       COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 6,1 SAY "And why &not? ALT+N" OF oDlg UPDATE SIZE 190, 12 ;
       COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 7,1 SAY "Victor && Casajuana Empresa Informatica Ltd." UPDATE ;
       SIZE 190, 12 COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW

    @ 9,1 SAY "<ESC> No Exit" UPDATE SIZE 50, 12 FONT oFnt ;
       COLOR GetSysColor( COLOR_HIGHLIGHT ), COLOR_BTNSHADOW
       
    @ 120, 70 BTNBMP oBot01 OF oDlg SIZE 60, 30 PROMPT "&Salida" ;
       FONT oFont FILE "..\bitmaps\Exit.bmp" RIGHT FLAT 2007     ;
       COLOR COLOR_BTNSHADOW ACTION( lWhen := .T., oDlg:End() )

    oBot01:cToolTip := "Use ALT + S Para Salir - Exit"

    oBot01:lCancel := .T.

    ACTIVATE DIALOG oDlg CENTERED VALID( lWhen )

    oFnt:End()
    oFont:End()

RETURN NIL

// FIN / END - kapiabafwh@gmail.com
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: ampersand

Postby VictorCasajuana » Wed Jun 14, 2023 9:17 am

Gracias por responder.

El problema es cuando muestro valores de una base de datos, por ejemplo, un fichero de artículos cuyo nombre contiene & ampersand:

Code: Select all  Expand view  RUN

#include 'fivewin.ch'

Function Main()

    DEFINE DIALOG oDlg TITLE "Test"

    cProduct_Name := 'Whisky J&B'

    @ 1,1 SAY cProduct_Name OF oDlg

    ACTIVATE DIALOG oDlg CENTERED

Return Nil
 


El resultado es el siguiente:
Image

Por este motivo, pregunto si en FW hay una función para "sanear" estos strings para mostrarlos en un SAY de un diálogo.

Si no la hay, la monto.

Salud!
--------
¿ Y porque no ?
¿ And why not ?
User avatar
VictorCasajuana
 
Posts: 268
Joined: Wed Mar 28, 2018 4:38 pm
Location: Vinaròs

Re: ampersand

Postby karinha » Wed Jun 14, 2023 10:27 am

Buén dia. Ah, SI! No que yo lo sepa. Use una function para eliminar el acento. Ejemplo:

Code: Select all  Expand view  RUN

FUNCTION ELIMINAR_ACENTOS( cStr )

   LOCAL cStrNew := "", nX

   cAcentos := {"ø","ƒ","Æ","Ç"," ","µ","…","·","‚","É","ê","ˆ","","Ò","í","Í","ó","¢","à","ä","å","“","â","ú","é","","š","ç","€","ã","Ã","á","Á","à","À","é","É","ê","Ê","í","Í","ó","Ó","õ","Õ","ô","Ô","ú","Ú","ü","Ü","ç","ù","AAO","§","¦","º","ª","€","‡","Ç","ç","'","`","ø","¡","Þ","×","Ø","ø", chr(239)}
   cLetras  := {"o","A","A","A","A","A","A","A","E","E","E","E","E","E","I","I","O","O","O","O","O","O","O","U","U","U","U","C","C","A","A","A","A","A","A","E","E","E","E","I","I","O","O","O","O","O","O","U","U","U","U","C"," ","CAO",".",".",".",".","C","C","C","C","" ,"" ,".","I","I","I","I","o",    ""   }

   For nX := 1 TO LEN(cAcentos)

      cStrNew := StrTran(cStr, cAcentos[nX], cLetras[nX])
      cStr    := cStrNew

   Next

RETURN( cStrNew )
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: ampersand

Postby karinha » Wed Jun 14, 2023 11:01 am

Listo:

Code: Select all  Expand view  RUN

// C:\FWH..\SAMPLES\VICTOR2.PRG

#include 'fivewin.ch'
#include "WColors.ch"

FUNCTION Main()

   LOCAL oDlg, cProduct_Name, cProdVentaFin, oFnt, oFont, oBot01

   cProduct_Name := 'Whisky J&B'  // PRODUCT.DBF

   cProdVentaFin := ELIMINAR_ACENTOS( cProduct_Name )

   DEFINE FONT oFnt  NAME "Ms Sans Serif"  SIZE 00, -12 BOLD
   DEFINE FONT oFont NAME "Ms Sans Serif"  SIZE 00, -16 BOLD

   DEFINE DIALOG oDlg TITLE "FiveWin: Victor Casajuana & And && Wow2()" ;
      SIZE 400, 320 FONT oFont COLOR CLR_BLACK, CLR_WHITE TRANSPARENT

   oDlg:lHelpIcon := .F.

    @ 1,1 SAY "Casajuana: Venta de Procuctos." OF oDlg UPDATE SIZE 190, 12 ;
       COLOR CLR_HRED, CLR_WHITE

   // Product Name:
   @ 3, 1 SAY cProdVentaFin OF oDlg UPDATE SIZE 190, 12 ;
       COLOR GetSysColor( COLOR_HIGHLIGHT ), CLR_WHITE

   @ 120, 70 BTNBMP oBot01 OF oDlg SIZE 60, 30 PROMPT "&Salida" ;
      FONT oFont FILE "..\bitmaps\Exit.bmp" RIGHT FLAT 2007     ;
      COLOR COLOR_BTNSHADOW ACTION( oDlg:End() )

   oBot01:cToolTip := "Use ALT + S Para Salir - Exit"

   oBot01:lCancel := .T.

   ACTIVATE DIALOG oDlg CENTERED

RETURN NIL

FUNCTION ELIMINAR_ACENTOS( cStr )

   LOCAL cStrNew := "", nX, cAcentos, cLetras

    // aqui Victor:
   cAcentos := { "&", "ø","ƒ","Æ","Ç"," ","µ","…","·","‚","É","ê","ˆ","","Ò","í","Í","ó","¢","à","ä","å","“","â","ú","é","","š","ç","€","ã","Ã","á","Á","à","À","é","É","ê","Ê","í","Í","ó","Ó","õ","Õ","ô","Ô","ú","Ú","ü","Ü","ç","ù","AAO","§","¦","º","ª","€","‡","Ç","ç","'","`","ø","¡","Þ","×","Ø","ø", CHR(239) }
   cLetras  := { "'&&'", "o","A","A","A","A","A","A","A","E","E","E","E","E","E","I","I","O","O","O","O","O","O","O","U","U","U","U","C","C","A","A","A","A","A","A","E","E","E","E","I","I","O","O","O","O","O","O","U","U","U","U","C"," ","CAO",".",".",".",".","C","C","C","C","" ,"" ,".","I","I","I","I","o",    "" }

   For nX := 1 TO LEN(cAcentos)

      cStrNew := StrTran(cStr, cAcentos[nX], cLetras[nX])
      cStr    := cStrNew

   Next

RETURN( cStrNew )

// FIN / END - kapiabafwh@gmail.com
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: ampersand

Postby VictorCasajuana » Wed Jun 14, 2023 11:17 am

Muchas gracias por la respuesta. Me montaré un pequeño replace & por &&

Salud!
--------
¿ Y porque no ?
¿ And why not ?
User avatar
VictorCasajuana
 
Posts: 268
Joined: Wed Mar 28, 2018 4:38 pm
Location: Vinaròs

Re: ampersand

Postby Carles » Wed Jun 14, 2023 11:27 am

V,

Canvia de Wisky... :D

C.
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1143
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: ampersand ( solucionado )

Postby VictorCasajuana » Wed Jun 14, 2023 11:53 am

Como apunte por si alguien llega hasta aquí:

Code: Select all  Expand view  RUN

strtran( ccadena, "&", "&&" ) // funciona ✅
 


Code: Select all  Expand view  RUN

hb_strreplace( ccadena,  { "&" => "&&" } ) // funciona ✅
 


Salud!
Last edited by VictorCasajuana on Wed Jun 14, 2023 12:46 pm, edited 1 time in total.
--------
¿ Y porque no ?
¿ And why not ?
User avatar
VictorCasajuana
 
Posts: 268
Joined: Wed Mar 28, 2018 4:38 pm
Location: Vinaròs

Re: ampersand

Postby VictorCasajuana » Wed Jun 14, 2023 11:54 am

Carles wrote:V,

Canvia de Wisky... :D

C.


El mejor whisky es el que te tomas con buena compañía, a ver si coincidimos. :wink:
--------
¿ Y porque no ?
¿ And why not ?
User avatar
VictorCasajuana
 
Posts: 268
Joined: Wed Mar 28, 2018 4:38 pm
Location: Vinaròs

Re: ampersand

Postby karinha » Wed Jun 14, 2023 12:43 pm

Code: Select all  Expand view  RUN

// C:\FWH..\SAMPLES\PETEWG.PRG

#include "FiveWin.ch"

/*
gsearch.prg - original fonte: https://hmgforum.com/viewtopic.php?t=7295&start=10
compile : hbmk2 -w3 -es2 gsearch
*/


FUNCTION Main( cSearchFor )

   LOCAL nResult

   nResult := GoogleSearch( hb_defaultValue( cSearchFor, "FiveWin Harbour -facebook" ) )

   IF nResult == 0

      MsgInfo( "Search string has been sent to your browser!", "Yes" )

   ELSE

      MsgStop( "Cannot execute search command! Error code:" + hb_ntos( nResult ), "No" )

   ENDIF

RETURN NIL

FUNCTION GoogleSearch( cSearchFor )

   LOCAL cCmd, nResult

   IF .NOT. HB_ISSTRING( cSearchFor ) .OR. Empty( cSearchFor )

      RETURN -1

   ENDIF

   cSearchFor := hb_StrReplace( cSearchFor, { '"' => "", " " => "+" }  )
   cCmd       := " /Q /C start https://www.google.com/search" + '"?client=gtx&q=' + cSearchFor + '"'
   nResult    := hb_run( hb_GetEnv( "ComSpec" ) + cCmd )

RETURN nResult

/*
FUNCTION StrReplace_Test()

   Local cText:=Replicate("*",1000)+"ABCD"+Replicate("+",1000)

   //? Len(cText) //2004

   //? "ABCD" $ cText //.T.

   cText := Hb_StrReplace( cText, {"ABCD"}, {"1234"} )

   ? Len(cText) // 2004?

   ? "1234" $ cText // .F. ?

RETURN NIL
*/

// FIN
 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests