Converting a string of zero length to a number?

Hi everyone,

I am practicing creating an automation to properly scrape a number of items off of a real estate listings website.
I am scraping the square footage of each of the properties and often times a handful of them contain no data and are logged as so in the Immediate table as: []

The output provides this: Assign: String cannot be of zero length

I’ve tried a number of ways to fix this to a 0 so I can pull out 0 values later from my scrape… but no luck.
I created a new variable Sqft set as a double.
The original assign I use under this if that detects whether the value is Null or Empty is the following Assign:

Sqft = Convert.ToDouble(row("Sqft").ToString.Replace("","0").Trim)

Additionally I tried in an Assign

Sqft = Cint(row("Sqft").ToString.Replace("","0").Trim)

Any ideas?

check the datatype of Sqft variable
i think it was in array type

If myStr.Trim.Length > 0
Then: convert it
Else: throw an error or do whatever else you need to do for empty values

Also, the Int32.TryParse(stringNumber, out output_Int32) is another option you can try.

Example:

stringNumber As String
stringNumber=String.Empty
output_Int32 as Int32

if Int32.TryParse(stringNumber, out output_Int32) Then
 WriteLine "Success! Integer value of String is " + output_Int32.ToString()
Else
 WriteLine "Blast! Failed to convert " + stringNumber + " to number!"
End If

You could use this in the Assign Activity

Boolean did_it_work = Int32.TryParse(stringNumber, out output_Int32)

Hi,

Can you try the following expression?

Sqft = if(Double.TryParse(row("Sqft").ToString(),New Double),Double.Parse(row("Sqft").ToString()),0)

img20211230-1

Regards,

1 Like

Hi @ajeffers,

Try to implement this syntax in your assign activity.

Sqft = If(String.IsNullorEmpty(row(“Sqft”).toString),0,row(“Sqft”).toString)

Thanks & Regards,
Urvesh Mistry

1 Like

Thank you! This worked perfectly.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.