Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

Ez-Script Escaping Specific Characters

what i want to do:

Code:


$pos = IndexOf($buffer, "\n")


this is what i tried without success

Code:


$pos = IndexOf($buffer, 0x0a)


i didn't find an equivalent function to:

Code:


$NewLine = char(13) + char(10)

AI Support Bot
Related Content
Synthiam
PRO
USA
#1  
i just went back & forward in the script help,
i went also to the learning section just to see if i was missing something.

but nothing come up.

I feel bad, it must be really simple...

I'll try tomorrow.
#2  
@ptp,
I am assuming you want to start a new line? Or create a break in speech?

Either way the best way to do that would be to place each "new line" in its own array index, this way you can call them individually, if need. The code below should help with that, I tried to comment it as much as possible to help you understanding the methodology.

Code:


# The string to be checked
$string = "Here is a few lines /n of code /n spanning across /n many lines."

# Create a temp string to modify as we go
$nextString = $string

# Find the length of the string
$len = Length( $string )

# We start reading the line at the 0 index
$min = 0

# Store our responses in an array
# To use them call $returnArray[0]
# The number in the [] is the index
DefineArray( $returnArray, 1 )

# Set our bool for our conditional test
$isNewLine = Contains($string, "/n")

# Start of the loop, basically mean if "/n" is in a
# new line keep loop
repeatwhile($isNewLine == true)

# Find the length of the string
$len = Length( $nextString )

# Adjust the length of the string for the new line(s)
$len = $len - $min

# Remove the pieces of the string we have already dealt with
$nextString = SubString( $nextString, $min, $len)

# Check if our new string still has a "/n"
$isNewLine = Contains($nextString, "/n")

# Rest our min to 0 since we are have stripped the string
# of char we have already dealt with
$min = 0

# A Conditional statement to make sure testing if we are on
# the last line to check
if ($isNewLine == true)

# Find where the "/n" is
$max = IndexOf( $nextString, "/n" )

# Get the string for each line
$tmpString = SubString($nextString, $min, $max)

# Set the min index so $nextString can get the next
# line we want to deal with
$min = $max + 2
else
# If we are on the last line we dont need to do anything
# to the code
$tmpString = $nextString

# Its done!
print("We are done here!")
endif

# Add the item to the array
AppendArray( $returnArray, $tmpString )

endrepeatwhile


I uploaded an example of this to the cloud if you want to see it working as well.
http://www.ez-robot.com/User/mikebmac/CloudFiles
It is called "Stripping /n"

Here is a picture of how the array turns out, along with any variables that are used.
User-inserted image
PRO
USA
#3  
@mikebmac

I didnt tested but my issue is:
i need the character \n (0x0a)

In your example does "/n" represents that character?

I didnt see anywhere "/" is the escaping char.
#4  
/n is just the string it looks for to escape and go to the next line. Just replace that with whatever you want to use. If you just need a forward slash replace the /n with just a "/". I have work at the moment, but I will try to update it after work to reflect that.
PRO
USA
#5  
thanks for helping the troubleshooting.

the main issue is how to create a string with the character ascii code 10 (0x0a).
PRO
Synthiam
#6  
EZ-Script originally wasn't designed for more than one line - the regex on the parser doesn't deal with that well. I'll revisit the parser and come up with something:)
#7  
Like JD said,
Strings can only be one line, but you can add a new line by using:

Code:


$fakeNLs = GetAsByte( 10 )


But you will not be able to save this to string as a variable because of the newlines in it. This is why I use arrays to get around this limitation, though if JD is going to add newline support that would be awesome.

Maybe something like C# with the @"String" would be nice.

Until then, I would recommend using the literal string "\n" and saving it as an array as shown above.

Sorry we couldn't get it to satisfaction... *blush*