25

Let's say we have two strings:

String1 = 'This is '
String2 = 'a mouse.'

How can I concatenate these 2 strings to form the string 'This is a mouse.' in gnuplot?

kenorb
  • 137,499
  • 74
  • 643
  • 694
GiniPig
  • 363
  • 1
  • 3
  • 7

1 Answers1

35

Given two strings

String1 = 'This is ' 
String2 = 'a mouse.'

To concatenate them, you can use either

String3 = String1.String2

or a more flexible:

String3 = sprintf("%s%s", String1, String2)

type help string or help sprintf for more information about the two methods.

bibi
  • 3,494
  • 4
  • 30
  • 45
  • 1
    I have a scenario where this does not work: When using `columnheader(1)`, it works in `plot ... title columnheader(1)` (as does `plot ... title "Avail."`), but it does not work trying to concatenate `columnheader(1)` and `"Avail."`. Message like `f_sprintf: attempt to print numeric value with string format`... (The first column of my data file contains a fixed string like `"/var"` (with those double-quotes)) – U. Windl Jun 04 '20 at 09:53
  • 1
    Found the solution: Using `columnhead(1)` instead of ` columnheader(1)` fixes the problem, even though I don't understand. – U. Windl Jun 08 '20 at 07:03