Inserting spaces intro datatable text row

-Hey gues, knocking my head over this one.
I have a datatable with 600+ rows in one column. Like this:
456874-645510008091Kontrollerahögnettolön.
698548-659810008091Kontrollerahögnettolön.
558744-887410008091Kontrollerahögnettolön.

Now, i’d like to insert spaces after the 11th character and after the 19th character so the it ends up like:
456874-6455 10008091 Kontrollerahögnettolön.
698548-6598 10008091Kontrollerahögnettolön.
558744-8874 10008091 Kontrollerahögnettolön.

Finding it tricky, any ideas?

thanks, tom

Fine
welcome to UiPath community
hope these steps would help you resolve this
–use excel application scope and pass the file path as input
–inside the scope use a read range activity and get theoutput with a variable of type datatable named dt
–now use a for each row loop and pass the datatable variable dt as input
–inside the loop use a assign activity like this
row(0).ToString = row(0).ToString.SubString(0,11)+" " +row(0).ToString.SubString(11,8)+" "+row(0).ToString.SubString(19,row(0).ToString.Length-19).ToString

Cheers @thomasb82

Hi, thanks for that! I’ve got the datatable set up like you said, but am getting an error as seen in the scrrenshot here:

might be over my head on this one :wink:

do i assign it to a new variable right? tried to change variable type to string but that produces an error saying it cnat convert from boolean to string.

may i know where this occured
Cheers @thomasb82

This is the exception error:
RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at UiPath.Core.Activities.ForEach`1.Execute(NativeActivityContext context)
at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance,
ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

and activitiinfo:

“Name”: “For Each Row”,
“Id”: “1.12”,
“InstanceId”: “9”,
“TypeName”: “UiPath.Core.Activities.ForEachRow”

no, you dont want to create a new datatable… you want to use assign inside a for each row with @Palaniyappan suggestion only…

Fine
Kindly check once whether the DTRow2 has any value in it
for that use WRITELINE activity and mention like this
DTRow2.Rows.Count.ToString
if this gives us more than 0 in the output panel then fine
else we need to check the excel file
and

try in sequence rather to flowchart (unless we dont have multiple decision making)

Cheers @thomasb82

Hey, yeah the writeline gives 10344 so that seems ok.
Created a new variable to hold the datatable: DTRaw. when i try to assign your suggestion to the DTRaw variable i get this error:

DTRaw is a system.data.datatable variable type.

ops that was in swedish :slight_smile: It says: cant convert values of the boolean type to system.data.datable.

1 Like

it must be like this
row(0) = the expression in assign activity
image

Cheers @thomasb82

i got the issue
in assign activity this must be in left side
row(0)

while this must be in right side of equal to in assign activity
row(0).ToString.SubString(0,11)+" " +row(0).ToString.SubString(11,8)+" "+row(0).ToString.SubString(19,row(0).ToString.Length-19).ToString

you were almost done
Cheers @thomasb82

oooh thanks, seems to be working now, it just needs to iterate through 600 rows :slightly_smiling_face:

I need to study more :slight_smile:

hmm. if if put row(0).toString i get this error message:
Anteckning3

if i put only row(0) it works but when running it i get this error message:

1 Like

yah it was a typo mistake
it should be only row(0) in the left side
fine
row(0).ToString.SubString(0,11)+" " +row(0).ToString.SubString(11,8)+" "+row(0).ToString.SubString(19,row(0).ToString.Length-19).ToString

this expression should work
is ADD HEADERS is enabled in the READ RANGE activity
Cheers @thomasb82

i dont think the error is about that typo tho, he most probably has some line that is shorter than expected…

yah will all the rows in excel have same length of string in it
@thomasb82

hey, yeah tried both with add headers and without,theres no headers in the datafile though, still same error. and no, not all lines are the same length,98% are though, one or two rows are longer…

that is they are all the same up until the 11th character, then there seems to be one or two that are different.but ive tried with just 5 rows that are the same and still seem to get the paramter length error…