Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Int point to string

Posted on 2006-04-20
6
Medium Priority
?
232 Views
Last Modified: 2010-04-16
Is there a way in C# to create an int pointer to a string or char array, for example:

string whatever = "test";
int * ptr = &whatever[0];

I need to then pass this address to a function which accepts int as input.  Thanks ahead of time.  Nick

0
Comment
Question by:nstefanov
  • 2
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16504801
What function? Is this API or managed function? Please give more details.
0
 

Author Comment

by:nstefanov
ID: 16504822
Just a custom function, something like this:

int customfunction(int firstaddress, int lastaddress)
{
   if (firstaddress == lastaddress)
       do something....
   else
      do something else
   return some int;
}

Then I want to pass from above &whatever[0], &whatever[whatever.lenght] like so

int result = customfunction(&whatever[0], &whatever[last]);

Thanks




0
 
LVL 48

Accepted Solution

by:
AlexFM earned 252 total points
ID: 16504868
I think that you are trying to reproduce some C++ algorithms in C#. But .NET string cannot be changed once it is creted, every function which is applied to string creates new string instance. I don't see a way to apply unsafe pointer to string characters, because string [] operator gives string character by value, and address of it is not address of string.
Take a look at String.ToCharArray function and String (Char[])  constructor, maybe this algorithm can work on char array.
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 248 total points
ID: 16505907
You can use string builder to marshal as an edittable string I believe.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question