473,739 Members | 7,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing an array to a function as a string parameter

I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert the string back into a 2-dimensional array. Example

Function1 {
int [,] TheArray[10,10];
Function2(TheAr ray.ToString();
}
Function2 (string parm) {
.... In here I would like to be able to convert parm back into a 2-dimensional int array. How do I do this
}

Appreciate your help,
Alex
Nov 16 '05 #1
3 2080
You could use the String.Join and String.Split. Although you probably have
your reason for doing this, keep in mind that this will not be as efficient
as just passing the reference to the array.

"Alex Munk" <Al******@discu ssions.microsof t.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert
the string back into a 2-dimensional array. Example
Function1 {
int [,] TheArray[10,10];
Function2(TheAr ray.ToString();
}
Function2 (string parm) {
... In here I would like to be able to convert parm back into a 2-dimensional int array. How do I do this }

Appreciate your help,
Alex

Nov 16 '05 #2
Yes, you can do it by coding it yourself. Is there a reason you just don't
pass the array? Conforming to an existing interface?

good luck,
kevin aubuchon

int [,] ar = new int[2,2];
int [,] az = new int[2,2];

ar[0,0] = 1;
ar[0,1] = 2;
ar[1,0] = 3;
ar[1,1] = 4;

StringBuilder sb = new System.Text.Str ingBuilder (100);
for (int i = 0; i < 2;i++)
{
for (int j=0; j < 2;j++)
{
sb.Append (ar[i,j].ToString("##") + ";");
}
}
string s = sb.ToString ();
char [] cs = {char.Parse (";")};

string [] lines = s.Split (cs);

for (int i = 0; i < 2;i++)
{
for (int j=0; j < 2;j++)
{
az[i,j] = Int32.Parse (lines[i * 2 + j]);
}
}
"Alex Munk" <Al******@discu ssions.microsof t.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert
the string back into a 2-dimensional array. Example
Function1 {
int [,] TheArray[10,10];
Function2(TheAr ray.ToString();
}
Function2 (string parm) {
... In here I would like to be able to convert parm back into a 2-dimensional int array. How do I do this }

Appreciate your help,
Alex

Nov 16 '05 #3
Another alternative is to use the BinaryFormatter .
eg :.
==
using System.IO;
using System.Runtime. Serialization.F ormatters.Binar y;
...
...
private string ConvertToBase64 String(int[,] data)
{
BinaryFormatter formatter = new BinaryFormatter ();
using(MemoryStr eam ms = new MemoryStream())
{
formatter.Seria lize(ms, data);

byte[] res = ms.ToArray();
return Convert.ToBase6 4String(res);
}
}

private int[,] ConvertFromBase 64String(string str)
{
byte[] res = Convert.FromBas e64String(str);

BinaryFormatter formatter = new BinaryFormatter ();

using(MemoryStr eam ms = new MemoryStream(re s))
{
return (int[,])formatter.Dese rialize(ms);
}
}
==

HTH,
Stephen
"Alex Munk" <Al******@discu ssions.microsof t.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert
the string back into a 2-dimensional array. Example
Function1 {
int [,] TheArray[10,10];
Function2(TheAr ray.ToString();
}
Function2 (string parm) {
... In here I would like to be able to convert parm back into a 2-dimensional int array. How do I do this }

Appreciate your help,
Alex

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14944
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
58
10167
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
8
4115
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
10
3167
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences in levels of indirection, so I feel it must have something to do with the way I am representing the array in the call and the return. Below I have commented the problem parts. Thanks in advance for any help offered. Pete
11
4465
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
2
15127
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to the outer function, the string.format sets the string-value "System.Object" at the position of {0}. How can i get it work, so that all my values, passed to the outer
11
8128
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
10
3931
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication eventname string source string ID string
0
1254
by: amazon | last post by:
I have web service that acceping following parameters.. postev.PostEvent(authentication as ws.authentication, name as string,id as string, exdate as date, parameter() as ws.nameparametervaluepair (I need help in passing this)) Postev.postEvent(auth(), "Test", "1234567", tdt, parameter()) For the first parameter authentication I have: Private Function auth() As ws.Authentication
13
2719
by: masso600 | last post by:
char word; in = fopen("test.txt", "r"); while(fscanf(in,"%s",&word)!=EOF) { /* Print all words */ /* printf("%s\n",&word); */
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.