Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiple lines of string to multiple parameters
#1
I want to implement a function to convert multiple lines of strings into multiple parameters
I created a member function str.CallCS
Currently, it only supports three lines of text (three parameters), but x.Call supports up to 10 parameters.

My method looks stupid
 
Code:
Copy      Help
,sel as.len
,,case 1 ret x.Call(_Fun as[0])
,,case 2 ret x.Call(_Fun as[0] as[1])
,,case 3 ret x.Call(_Fun as[0] as[1] as[2])
,,;......

Is there a simpler and smarter solution?

PS: This function may not be suitable, but sometimes I need the requirement for multiple unknown numbers of parameters

Thanks in advance for any suggestions and help
david

Macro Test
 
Code:
Copy      Help
_s=
;using System;
;
;public class cla
;{
;,public static string Fun1(string str1)
;,{
;,,string result = str1;
;,,Console.WriteLine(result);
;,,return result;
;,}
;
;,public static string Fun2(string str1, string str2)
;,{
;,,string result = str1 + str2;
;,,Console.WriteLine(result);
;,,return result;
;,}
;
;,public static string Fun3(string str1, string str2, string str3)
;,{
;,,string result = str1 + str2 + str3;
;,,Console.WriteLine(result);
;,,return result;
;,}
;}

;1 arg
str args=
;first parameter
_s.CallCS("Fun1" args)

;2 args
args=
;first parameter
;second parameter
_s.CallCS("Fun2" args)

;3 args
args=
;first parameter
;second parameter
;Third parameter
_s.CallCS("Fun3" args)

Member function str.CallCS
Code:
Copy      Help
function~ str'_Fun [str'_Arg]

CsScript x.AddCode(this)

if _Arg.len
,ARRAY(str) as=_Arg
,sel as.len
,,case 1 ret x.Call(_Fun as[0])
,,case 2 ret x.Call(_Fun as[0] as[1])
,,case 3 ret x.Call(_Fun as[0] as[1] as[2])
else
,ret x.Call(_Fun)


Messages In This Thread
multiple lines of string to multiple parameters - by Davider - 05-08-2023, 01:18 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)