web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Unable to replace backslash(\) from my string

(0) ShareShare
ReportReport
Posted on by 25

Hi,

I am unable to remove backslash(\) from my string. 

Input String:

"[ {\"SalesId\":\"CNMF-000001\",\"Currency Code\":\"CNY\",\"CustAccount\":\"CNMF-000001\"}\"
Expected Output:
"[ {"SalesId":"CNMF-000001","Currency Code":"CNY","CustAccount":"CNMF-000001"}"
I tried with replace method but its not working
sJSON = strReplace(json, @"\", " ");
Kindly suggest me.
Best Regards,
Andavar
I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Andavar,

    Could you, please, explain a bit what is the source of the string? It looks like backslash in this case is an escape character and you don't need to remove it.

  • Andavar Profile Picture
    25 on at

    Hi,

    I have formed data through database fields into Jason string, while forming Jason string my output values returning with escape character backslash(\) . I am not sure why this escape characters are appearing in my return values. But I need the output without escape character backslash(\).

    Source Code

    System.IO.StringWriter          stringWriter;

           Newtonsoft.Json.JsonTextWriter  jsonWriter;

           str sJSON = "" , json = "";

           container desiredCompanies = [Company];

           SalesTable salestable;

           List list = new List(Types::anytype);

            ;

           stringWriter       = new System.IO.StringWriter();

           jsonWriter         = new Newtonsoft.Json.JsonTextWriter(stringWriter);

           while  select crossCompany:desiredCompanies * from salestable where salesTable.salesstatus ==3

           {

             jsonWriter.WriteStartObject();

             jsonWriter.WritePropertyName("SalesId");

             jsonWriter.WriteValue(strRTrim(strLTrim(salestable.salesid)));

             jsonWriter.WritePropertyName("Currency Code");

             jsonWriter.WriteValue(strRTrim(strLTrim(salestable.currencycode)));

             jsonWriter.WritePropertyName("CustAccount");

             jsonWriter.WriteValue(strRTrim(strLTrim(salestable.CustAccount)));

             jsonWriter.WriteEndObject();

             jsonWriter.WriteValue(",");

          }

           sJSON = stringWriter.ToString();

           Info(strFmt("%1", stringWriter.ToString()));

            return sJSON;

    Current Return Values in Jason format

    "{\"SalesId\":\"CNMF-000002\",\"Currency Code\":\"CNY\",\"CustAccount\":\"CNMF-000001\"}\"

    Expected output without backslash(\)

    "{"SalesId":"CNMF-000002","Currency Code":"CNY","CustAccount":"CNMF-000001"}"

    Kindly suggest me how we can achieve this

    Best Regards,

    Andavar

  • Suggested answer
    Muthusamy Profile Picture
    4 on at

    Hi,

    You can use strReplace  method to exclude the backslash character from the output string.

    check this blog have some expample. d365solution.blogspot.com/.../remove-special-character-from-string-in.html

    Thanks,

  • Andavar Profile Picture
    25 on at

    Hi ,

    My current return values comes with double quotation (") both beginning and ending . I have to return without double quotation.

    Return values

    "{"SalesId":"CNMF-000002","Currency Code":"CNY","CustAccount":"CNMF-000001"}"

    Expected return values

    {"SalesId":"CNMF-000002","Currency Code":"CNY","CustAccount":"CNMF-000001"}

    Please be note, my method is returning string

    Kindly advise me how we can achieve this.

    Best Regards,

    Andavar

  • Blue Wang Profile Picture
    on at

    Hi Andavar,

    You said "{"SalesId":"CNMF-000002","Currency Code":"CNY","CustAccount":"CNMF-000001"}" is in Visual Studio debugger?

    It is not the actual string value, try to print it to determine the specific value.

    That should be displayed according to your requirements.

    {"SalesId":"CNMF-000002","Currency Code":"CNY","CustAccount":"CNMF-000001"}

  • Andavar Profile Picture
    25 on at

    Hi ,

    I have formed the Jason data through  Newtonsoft.Json.JsonTextWriter and I have tried both FormJsonSerializer and Newtonsoft.Json.JsonConvert::SerializeObject(empObj) but I could not framed exact jason format

    Current Return Values in Jason format

    "{\"SalesId\":\"CNMF-000002\",\"Currency Code\":\"CNY\",\"CustAccount\":\"CNMF-000001\"}\"

    Expected output with proper jason format

    {"SalesId":"CNMF-000002","Currency Code":"CNY","CustAccount":"CNMF-000001"}

    Best Regards,

    Andavar

  • Suggested answer
    Muthusamy Profile Picture
    4 on at

    Hi,

    You can use the strRem Function to remove the character from string. If its a common character, you can find the character position to remove it.

    Check this blog, d365solution.blogspot.com/.../remove-first-characters-in-d365-ax-2012.html

    Thanks,

  • Andavar Profile Picture
    25 on at

    Hi ,

    Its actually my method returns with double quotes(") while I am checking the service in Postman. Kindly suggest me, method return value can we have a return value as object.

    Best Regards,

    Andavar

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans