Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Problem with insertion and splitting

zak100

Coder
Hi,
I have a string: "address payable dest , uint amount". I want to split it such that:
arr[0][0] = address payable
arr[0][1] = dest
arr[1][0] = uint
arr[1][1] = amount

I have written the following code:


Code:
const path = require("path");

const fs = require("fs");

module.exports = async function(callback)

{

   try {

      let argStrWithComma = "address payable dest , uint amount"

      let argStrN=[[],[]]

      let argStrWithCommaBrok = []

      let addrPayTypeAndVar = []

      let uintTypeAndVar = []

      let index =0

      let len =0

      let ptOfInsMarkChar = 0

      console.log("Implement the code for dealing with arguments having address payable")

      console.log("value of str =" + argStrWithComma)

      argStrWithCommaBrok = argStrWithComma.split(',');

      console.log("argStrWithCommaBrok[0]="+argStrWithCommaBrok[0]+ "argStrWithCommaBrok[1]" + argStrWithCommaBrok[1])

      if(argStrWithCommaBrok[0]. search ("address") >= 0){

         index = argStrWithCommaBrok[0].indexOf("address payable")

         len = "address payble".length

         ptOfInsMarkChar = len + index +1

         argStrWithCommaBrok[0].slice(0,index) + " # " + argStrWithCommaBrok[0].slice(index)

         addrPayTypeAndVar = argStrWithCommaBrok[0].split("#")

      }   

      else{

         index = argStrWithCommaBrok[0].indexOf("address payable")

         len = "address payble".length

         ptOfInsMarkChar = len + index +1

         argStrWithCommaBrok[0].slice(0,index) + " # " + argStrWithCommaBrok[0].slice(index)

         addrPayTypeAndVar = argStrWithCommaBrok[1].split("#")

      }

      if(argStrWithCommaBrok[0]. search ("uint") >= 0){

         uintTypeAndVar = argStrWithCommaBrok[0].split(" ")

      }

      else{

         uintTypeAndVar = argStrWithCommaBrok[1].split(" ")

      }

      argStrN[0][0] = addPayTypeAndVar[0]

      argStrN[0][1] = addPayTypeAndVar[1]

      argStrN[1][0] = uintTypeAndVar[0]

      argStrN[1][1] = uintTypeAndVar[1]

      console.log("###?? argStrN"+ argStrN)

      }

      catch(error){

         console.log(error)

      }
The output is:
 
Implement the code for dealing with arguments having address payable
value of str =address payable dest , uint amount
argStrWithCommaBrok[0]=address payable dest argStrWithCommaBrok[1] uint amount
index = 0
len of address payable is14
ptOfInsMarkChar 15
1argStrWithCommaBrok[0]address payable dest
addrPayTypeAndVaraddress payable dest
###?? argStrNaddress payable dest ,,,uint
 

New Threads

Buy us a coffee!

Back
Top Bottom