stringbykey issue

Hello All,

im having trouble trying to get stringbykey to return the right line of a string for me. ideally I'd like the function to return just "18:42:05"

#pragma rtGlobals=1     // Use modern global access method.
function getstringtime(inwave)

wave inwave
string  wavenote = note(inwave)
string timestring= stringbykey("TIME", wavenote, "=", ";")


print itemsinlist(wavenote,";")
Print timestring

END


The string wavenote has the form
VERSION = 0;
DATE = 4.Sep 2015;
TIME = 18:42:05;
SCAN_MODE = EDC;
ADC0 = 0;
ADC1 = 0;
RANGE_NUM = 1;
MONO_START_1 = -1.0;
MONO_END_1 = -1.0;
MICRO_START_1 = 10.0;
MICRO_END_1 = 30.0;
POINTS_1 = 41;
DIFFERENZ = 5.0;
TIME_PERIODE = 0.0;
SCANS = 1;
X_START = 1;
X_SIZE = 1600;
Y_START = 1;
Y_SIZE = 1200;
DATA_FORMAT = 2;
INTERATION_TIME = 1000;
AVERAGES = 0;
SAVE_MODE = 2;

ROI_X_START = 1;
ROI_X_SIZE = 1600;
ROI_Y_START = 1;
ROI_Y_SIZE = 1200;
ONLINE_INTENSITY = true;
COMMENT = ;
HORI_BINNING = 1;
VERTI_BINNING = 1;



Update,

I know that stringmatch(wavenote,"*TIME*") does return a value of 1 so the KeyStr "TIME" should work. Maybe it has something to do with the spaces in the string "TIME = 18:42:05;" not "TIME=18:42:05;" ?????
Update,

OK I figured out the problem, by placing the string on one line the code now works. The problem is that its the program that makes the file that separates all of these values on to seperate lines with the [] symbol. I cant change that, so i have to figure out a way to remove it all when i load in my files.

any suggestions would be appreciated
update

My code works! until i save it. then it deletes this square character when i save it and the function no longer works. it wont let me type the square(it just adds a carriage return) so i will use [].

function getstringtime(inwave)
wave inwave
string  wavenote = note(inwave)
String replace= "[]"

string newwavenote = replacestring(replace,wavenote,"")
String Date_stamp=stringbykey("DATE =",newwavenote," ",";")
String Time_stamp = stringbykey("TIME =",newwavenote," ", ";")
String IntegrationTime = stringbykey("INTERATION_TIME =",newwavenote," ",";")

String FinalNote = "Date:"+Date_Stamp+";" +"Time:"+Time_Stamp +","+"Integration_Time:"+ IntegrationTime+";"
Print FinalNote

Note /k inwave,FinalNote

END


I've tried adding "/r" but that doesnt work, does anyone know how to explicitly program a carriage return??

Thanks
This works:
String/G test = "IDENT = SMART;VERSION = 0;DATE = 4 Sep 2015;"
Print StringByKey("IDENT", test, "=")
  SMART
Print StringByKey("VERSION", test, "=")
  0
Print StringByKey("DATE", test, "=")
  4 Sep 2015


From your screen dump, it looks like your keyword/value list has a linefeed after each semicolon. I get the same printout with this:
String/G test = "IDENT = SMART;\nVERSION = 0;\nDATE = 4 Sep 2015;\n"
Print test


You should remove the linefeeds, like this:
test = ReplaceString("\n", test, "")
Print test


Then StringByKey should work.

I'm not sure why StringByKey works with in your keyword/value list. I would replace it with just equal, like this:
test = ReplaceString(" = ", test, "=")
Print test

hrodstein wrote:
This works:
String/G test = "IDENT = SMART;VERSION = 0;DATE = 4 Sep 2015;"
Print StringByKey("IDENT", test, "=")
  SMART
Print StringByKey("VERSION", test, "=")
  0
Print StringByKey("DATE", test, "=")
  4 Sep 2015


From your screen dump, it looks like your keyword/value list has a linefeed after each semicolon. I get the same printout with this:
String/G test = "IDENT = SMART;\nVERSION = 0;\nDATE = 4 Sep 2015;\n"
Print test


You should remove the linefeeds, like this:
test = ReplaceString("\n", test, "")
Print test


Then StringByKey should work.

I'm not sure why StringByKey works with in your keyword/value list. I would replace it with just equal, like this:
test = ReplaceString(" = ", test, "=")
Print test

Hi hrodstein,

This would indeed work (As does my code) but unfortunately not in regards to this stupid [] character because the "replacestring" funcition would be looking for /n in the wavenote, which isn't there. Only this [] character.

Thanks for the help though

Simon