Jump to content

The problem of StringReplace


Recommended Posts

Hello my friends Sorry about my English , Why are not replaced any character to "é"

 

#include <WinAPIFiles.au3>
_WinAPI_Wow64EnableWow64FsRedirection(False)
$var = StringReplace("connect,",",","é") ; this worked
MsgBox(0,"",$var) 

$stdoutRead = StringReplace(_CmdResult('netsh mbn show interface'),",","é") ;why not replaced

MsgBox(0,"",$stdoutRead)
Func _CmdResult($Commands)
    Local $Message
Local $DOS = Run(@ComSpec & " /c "&  $Commands , "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($DOS)
$Message = StdoutRead($DOS)
Return $Message
EndFunc

 

Link to comment
Share on other sites

  • Developers
3 minutes ago, dikart7 said:

Why are not replaced any character to "é"

Any character or do you mean a COMMA as that is what you have defined in the StringReplace() command?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Sorry, but that doesn't answer my question. ;) 
what exactly are you trying to accomplish?
what is the exact content of the STDOUT
 

#include <WinAPIFiles.au3>

$stdoutRead = _CmdResult('netsh mbn show interface')
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $stdoutRead = ' & $stdoutRead & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$stdoutRead = StringReplace($stdoutRead, ",", "é") ;why not replaced
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $stdoutRead = ' & $stdoutRead & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

MsgBox(0, "", $stdoutRead)
Func _CmdResult($Commands)
    Local $Message
    Local $DOS = Run(@ComSpec & " /c " & $Commands, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWaitClose($DOS)
    $Message = StdoutRead($DOS)
    Return $Message
EndFunc   ;==>_CmdResult

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@@ Debug(4) : $stdoutRead =
Le systŠme dispose d'une interfaceÿ:

    Nom               : Connexion haut d‚bit mobile 13
    Description        : HUAWEI Mobile Connect - 3G Network Card
    GUID               : {DD2C1976-A1DC-43F4-845F-67C6244A4CAA}
    Adresse physique   : 00:1e:10:1f:79:c9
    tat              : pas connect‚
    Type d'appareil        : L'appareil haut d‚bit mobile est amovible.
    Classe cellulaire     : CDMA
    ID de l'appareil          : 802b9a56
    Fabricant       : HUAWEI TECHNOLOGIES CO.
    ModŠle              : EC156
    Version de micrologiciel   : 11.106.33.00.000
    Nom de fournisseur      : CDMA
    Itin‚rance            : pas d'itin‚rance
    Signal             : 70%


>Error code: 0
@@ Debug(6) : $stdoutRead =
Le systŠme dispose d'une interfaceÿ:

    Nom               : Connexion haut d‚bit mobile 13
    Description        : HUAWEI Mobile Connect - 3G Network Card
    GUID               : {DD2C1976-A1DC-43F4-845F-67C6244A4CAA}
    Adresse physique   : 00:1e:10:1f:79:c9
    tat              : pas connect‚
    Type d'appareil        : L'appareil haut d‚bit mobile est amovible.
    Classe cellulaire     : CDMA
    ID de l'appareil          : 802b9a56
    Fabricant       : HUAWEI TECHNOLOGIES CO.
    ModŠle              : EC156
    Version de micrologiciel   : 11.106.33.00.000
    Nom de fournisseur      : CDMA
    Itin‚rance            : pas d'itin‚rance
    Signal             : 70%

 

Link to comment
Share on other sites

  • Developers

This has everything to do with character encoding. I have attached the same script with 2 different StringReplace() statements.
the first doesn't work and the second works and that is because the first one has an ASCII COMMA and the second an UTF8 COMMA.

Give it a try.

Jos

test.au3

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

It actually looks like it is an ASCII highvalue character and not a UTF character. This character has an ASCII 130 value so this should work:

$stdoutRead = StringReplace($stdoutRead, chr(130), "é") ;why not replaced

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It should work fine with this :

#include <WinAPIFiles.au3>
_WinAPI_Wow64EnableWow64FsRedirection(False)

Local $iPid = Run(@ComSpec & " /c netsh mbn show interface", @SystemDir, "", $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($iPid)
Local $sResult = StdoutRead($iPid)

MsgBox(0, "", _OEMToAnsi($sResult) )



Func _OEMToAnsi($sOEM)
    Local $a_AnsiFName = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $sOEM, 'str', '')
    If @error = 0 Then $sAnsi = $a_AnsiFName[2]
    Return $sAnsi
EndFunc   ;==>_OEMToAnsi

 

Link to comment
Share on other sites

On 10/03/2017 at 3:00 PM, jguinch said:

It should work fine with this :

#include <WinAPIFiles.au3>
_WinAPI_Wow64EnableWow64FsRedirection(False)

Local $iPid = Run(@ComSpec & " /c netsh mbn show interface", @SystemDir, "", $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($iPid)
Local $sResult = StdoutRead($iPid)

MsgBox(0, "", _OEMToAnsi($sResult) )



Func _OEMToAnsi($sOEM)
    Local $a_AnsiFName = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $sOEM, 'str', '')
    If @error = 0 Then $sAnsi = $a_AnsiFName[2]
    Return $sAnsi
EndFunc   ;==>_OEMToAnsi

 

Thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...