How to pass runtime variable (datetime) in scala?

124 views
Skip to first unread message

pmour...@gmail.com

unread,
Jun 22, 2016, 11:46:35 AM6/22/16
to scala-user
import java.util.Calendar

val timestamp = Calendar.getInstance.getTime   \\ I have defined the timestamp variable


Following my request which i wanted to pass the runtime datetime value.


.exec(http("request_6")
.post("/abcd/projects")
.headers(headers_29)
.formParam("Id", "5")
.formParam("extra", """{"inputproname":"+timestamp+","textareadesc":""")) \\ passing the same timestamp here


Scala script has been successfully executed but it created as name with << +timestamp+ >> instead of actual timestamp value


So can anyone tell me what am i doing wrong here? how to pass the time timestamp variable ???


Your help would be much appreciated.



Thanks in advance

Praveen

Rex Kerr

unread,
Jun 23, 2016, 1:59:28 PM6/23/16
to pmour...@gmail.com, scala-user
You need to open/close triple quotes, not single quotes, around the variable name.
"""blah""" + foo + """lalala"""

Everything inside triple quotes is considered to be a literal string.

  --Rex


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clint Gilbert

unread,
Jun 23, 2016, 2:08:41 PM6/23/16
to scala...@googlegroups.com
Alternatively, use string interpolation:

scala> val foo = 42
foo: Int = 42

scala> s"""{"foo":$foo}"""
res0: String = {"foo":42}

(note the 's'.) Rex is absolutely right about the effects of
triple-quotes, also.

PS: You might also consider a JSON lib. It should handle things like
escaping quotes inside variables like 'foo' or 'timestamp' and lots of
other gotchas.

On 06/23/2016 01:59 PM, Rex Kerr wrote:
> You need to open/close triple quotes, not single quotes, around the
> variable name.
> """blah""" + foo + """lalala"""
>
> Everything inside triple quotes is considered to be a literal string.
>
> --Rex
>
>
> On Wed, Jun 22, 2016 at 2:05 AM, <pmour...@gmail.com
> <mailto:pmour...@gmail.com>> wrote:
>
> |importjava.util.Calendarvaltimestamp =Calendar.getInstance.getTime
> \\I have defined the timestamp variable|
>
>
> Following my request which i wanted to pass the runtime datetime value.
>
>
> |.exec(http("request_6").post("/abcd/projects").headers(headers_29).formParam("Id","5").formParam("extra","""{"inputproname":"+timestamp+","textareadesc":"""))\\passing
> the same timestamp here|
>
>
> Scala script has been successfully executed but it created as name
> with << +timestamp+ >> instead of actual timestamp value
>
>
> So can anyone tell me what am i doing wrong here? how to pass the
> time timestamp variable ???
>
>
> Your help would be much appreciated.
>
>
>
> Thanks in advance
>
> Praveen
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to scala-user+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scala-user+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--



signature.asc
Reply all
Reply to author
Forward
0 new messages