Android Question Regex.replace " " with 60h

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone,
Could anybody help me how to replace space with 60h ?
I'm working on integration with an API , if a send a string that contain " "(space) the API replace with +
Based on the documentation description :"NamePLU - 30 symbols for article's name plus separator for MU=60h"
B4X:
If PLUName.Contains(" ") Then
        PLUName= Regex.Replace(" ",PLUName,"\<")
    End If
 

teddybear

Well-Known Member
Licensed User
You don't need to escape the “<"
B4X:
 PLUName= Regex.Replace(" ",PLUName,"<")
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Where is the "&" from? could you post the project?
I think it is useless to post the project , because my app communicate with an API witch is connected to a cash register.
This is the the documentation
XML:
<Command Name="SellPLUwithSpecifiedVAT" CmdByte="0x31">

  <FPOperation>Register the sell (for correction use minus sign in the price field) of article with specified name, price, quantity, VAT class and/or discount/addition on the transaction.</FPOperation>

  <Args>

    <Arg Name="NamePLU" Value="" Type="Text" MaxLen="36">

      <Desc>30 symbols for article's name plus separator for MU=60h

followed up to 3 symbols for unit plus 2 symbols spaces</Desc>

    </Arg>

    <Arg Name="OptionVATClass" Value="" Type="Option" MaxLen="1">

      <Options>

        <Option Name="Alte taxe" Value="F" />

        <Option Name="VAT Class A" Value="A" />

        <Option Name="VAT Class B" Value="B" />

        <Option Name="VAT Class C" Value="C" />

        <Option Name="VAT Class D" Value="D" />

        <Option Name="VAT Class E" Value="E" />

      </Options>

      <Desc>1 symbol for article's VAT class with optional values:

 - 'A' - VAT Class A

 - 'B' - VAT Class B

 - 'C' - VAT Class C

 - 'D' - VAT Class D

 - 'E' - VAT Class E

 - 'F' - Alte taxe</Desc>

    </Arg>

    <Arg Name="Price" Value="" Type="Decimal" MaxLen="10">

      <Desc>1 to 10 symbols for article's price</Desc>

    </Arg>

    <Arg Name="Quantity" Value="" Type="Decimal" MaxLen="10">

      <Desc>1 to 10 symbols for quantity</Desc>

      <Meta MinLen="1" Compulsory="false" ValIndicatingPresence="*" />

    </Arg>

    <Arg Name="DiscAddP" Value="" Type="Decimal" MaxLen="7">

      <Desc>1 to 7 for percentage of discount/addition</Desc>

      <Meta MinLen="1" Compulsory="false" ValIndicatingPresence="," />

    </Arg>

    <Arg Name="DiscAddV" Value="" Type="Decimal" MaxLen="8">

      <Desc>1 to 8 for value of discount/addition</Desc>

      <Meta MinLen="1" Compulsory="false" ValIndicatingPresence=":" />

    </Arg>

    <Arg Name="DiscNamed" Value="" Type="Decimal" MaxLen="8">

      <Desc>1 to 8 symbols for value of named discount</Desc>

      <Meta MinLen="1" Compulsory="false" ValIndicatingPresence="@" />

    </Arg>

    <Arg Name="Category" Value="" Type="Decimal_with_format" MaxLen="7" Format="0000.00">

      <Desc>Up to 7 symbols for PLU Category code in format ####.##</Desc>

      <Meta MinLen="1" Compulsory="false" ValIndicatingPresence="+" />

    </Arg>

    <Arg Name="NamePLUextension" Value="" Type="Text" MaxLen="12">

      <Desc>12 symbols for extension of the PLU Name: FP Only</Desc>

      <Meta MinLen="12" Compulsory="false" ValIndicatingPresence="!" />

    </Arg>

    <Arg Name="AdditionalNamePLU" Value="" Type="Text" MaxLen="108">

      <Desc>108 symbols for additional PLU name</Desc>

      <Meta MinLen="108" Compulsory="false" ValIndicatingPresence=";" />

    </Arg>

    <ArgsFormatRaw><![CDATA[ <NamePLU[36]> <;> <OptionVATClass[1]> <;> <Price[1..10]>  {<'*'> <Quantity[1..10]>} {<','> <DiscAddP[1..7]>} {<':'><DiscAddV[1..8]>} {<'@'><DiscNamed[1..8]>} {<'+'><Category[1..7]>} {<'!'><NamePLUextension[12]>} {<;><AdditionalNamePLU[108]> } ]]></ArgsFormatRaw>

  </Args>

</Command>
Below you can see the main part of communication
B4X:
Sub Submit_Action(command As String)As ResumableSub 
    'Dim command As String = "SellPLUWithSpecifiedVat(NamePLU=Article1,OptionVATClass=A,Price=10.2,Quantity=1,DiscAddP=0,DiscAddV=0)"
    Dim command As String = command' "CashPayCloseReceipt()"
    Dim su As StringUtils
    command = su.EncodeUrl(command, "UTF-8")
    Dim j As HttpJob
    j.Initialize("",Me )
    j.Download("http://localhost:4444/" & command)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString) 
        Return Code
    End If
    j.Release
End Sub

B4X:
Public Sub sellItem(PLUName As String,VATRate As String,UnitPrice As String,quantity As String,DiscProc As String,DiscVal As String) As String
    If PLUName.Contains(" ") Then
        PLUName= Regex.Replace(" ",PLUName,"<")
    End If
    Return $"SellPLUWithSpecifiedVat(NamePLU=${PLUName},OptionVATClass=${VATRate}$,Price=${UnitPrice},quantity=${quantity},DiscAddP=${DiscProc},DiscAddV=${DiscVal})"$
End Sub
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I mean that you post a snippet like this
B4X:
 Dim PLUName as String="TEST 3"
 PLUName= Regex.Replace(" ",PLUName,"<")
 log(PLUName)
what is the result?
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
I mean that you post a snippet like this
B4X:
 Dim PLUName as String="TEST 3"
 PLUName= Regex.Replace(" ",PLUName,"<")
 log(PLUName)
what is the result?
Here is the log result : TEST<3
And here is the printed line by device :
1683276377153.png
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Can you not just use
B4X:
PLUName = PLUName.Replace(" ","+")

As you said it replaces spaces with '+' not a '<'
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
As it is sent to a web address you may find you need to send
B4X:
PLUName = PLUName.Replace(" ","%20")
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Have a look at url encoding for which chars can appear in a web address line.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
it's working
check this for a more complete list

 
Upvote 0
Top