c# convert string to array on char(253) deliminator [duplicate] - c#

This question already has answers here:
How do i split a String into multiple values?
(5 answers)
Closed 3 years ago.
Not entirely sure the following code is going to help many people, but here goes
try
{
uvConnect = UniObjects.OpenSession(serverId, sUser, sPass, sAcct, "uvcs");
// Open Movie File
UniFile uvFile = uvConnect.CreateUniFile("MOVIES");
UniDynArray movieRec = uvFile.Read(txtMovieId.Text);
string sMovieData = movieRec.StringValue;
MessageBox.Show(sMovieData);
}
sMovieData contains a single string of the entire record retrieve from MOVIES file, each field is deliminated by a char(253) character in the database I am using.
Is there a function/method/etc to convert the string to an array using char(253) as a value deliminator

Something like this should work:
string[] fields = sMovieData.Split((char)253);

Try this... string[] arrayValues = "stringToConvertToArray".Split((char)253);

Related

C# Selecting part of string when there is a matching result in part of the string [duplicate]

This question already has answers here:
Get URL parameters from a string in .NET
(17 answers)
Closed 5 years ago.
I have a string which basically looks like this:
/giveaway/host/setup/ref=aga_h_su_dp?_encoding=UTF8&value_id=1484778065
The trick here is that the length of the string can vary and will change... However the part with "value_id=something" always stays same... So the problem that I ran in was that I can do something like this:
var myId = string.SubString(30,45);
to get the value after value_id= /*this one here*/
I'm thinking that this can be solved by regex or some other way, but I'm not too sure how to write such one. Can someone help me out?
Could you try this. If your value_id always the last of your string you can use this.
var str = "/giveaway/host/setup/ref=aga_h_su_dp?_encoding=UTF8&value_id=1484778065";
var valueId = str.Split('=').LastOrDefault();
Result : 1484778065
Hope it's help to you
You can split by 'value_id='
string[] tokens = str.Split(new[] { "value_id=" }, StringSplitOptions.None);
if(tokens.Length>1){
//parse tokens[1] with the value
}

Stuck in a loop updating a value [duplicate]

This question already has answers here:
C# string replace does not actually replace the value in the string [duplicate]
(3 answers)
Closed 5 years ago.
I have an application that updates values in documents, however, some of these documents have multiple entries of this value. due to this I have created a Do Something loop but this is just looping and is not replacing the values.
my code is as below:
do
{
int dollarIndex = script.IndexOf("$");
string nextTenChars = script.Substring(dollarIndex - 17, 17);
string promptValue = CreateInput.ShowDialog(nextTenChars, "Input");
script.Replace("$", promptValue);
}
while (script.Contains("$"));
Strings are immutable, so you need to do:
script = script.Replace("$", promptValue);
Simply doing
script.Replace("$", promptValue);
Doesn't update the value of script

How to check if List contains part of a value? [duplicate]

This question already has answers here:
Find substring in a list of strings
(6 answers)
Closed 6 years ago.
I was wondering if it possible to check if a List contains part of a value. If it finds the value then return the value.
E.g. If the List had values 12345, 14567 and 14785, I want to search if the List contains '123',
Is this possible?
If it is can all values that contain '123' be returned?
This is how I add values to the List:
recordFailedPO.Add(Convert.ToInt32(dataGWHeight.Rows[0].Cells[0].Value));
This is how I'm checking for a part of a value:
if (recordFailedPO.Contains(currentPO))
{
// Code Here
}
Where currentPO is the user input.
Thanks for any help
In that case you could use string Contains method
var containsNumber = recordFailedPO.Where(x => x.ToString().Contains("123"));
try to convert to string before
int res = recordFailedPO.Find(x=>x.ToString().Contains(currentPO));
All values can be returned by FindAll .
List<int> res = recordPO.FindAll(x=>x.ToString().Contains(currentPO)):

Invalid string in C# [duplicate]

This question already has answers here:
What's the # in front of a string in C#?
(9 answers)
Closed 7 years ago.
How come this string is valid to open with VLC via a Process:
string fileToPlay = #"C:\Videos\Movies\Movie title.avi";
But this one isn't:
string fileToPlay = #myMovie;
Where the value of the variable myMovie is
"C:\Videos\Movies\Movie title.avi"
Process.Start(vlcPath, fileToPlay );
The problem is that you can only use the # character when placed against string literals like this:
string path = #"c:\temp";
It can be used when placed against a string variable, as you have done, but it has a different meaning. In that case, it is used when you choose an identifier which matches a C# keyword, like this:
string #class = "hello";
You can read more about it here: https://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx

How to get 4 digits from the middle a string in C# [duplicate]

This question already has answers here:
How to get the last five characters of a string using Substring() in C#?
(12 answers)
Closed 8 years ago.
I have a string variable like test10015, i want to get just the 4 digits 1001,
what is the best way to do it?
i"m working in asp.net c#
With Linq:
var expected = str.Skip(4).Take(4);
Without Linq:
var expected = str.Substring(4,4);
Select the first four digits in your string:
string str = "test10015";
string strNum = new string(str.Where(c => char.IsDigit(c)).Take(4).ToArray());
You can use String.Substring Method (Int32, Int32). You can subtract 5 from from the length to start from your required index. Make sure the format of string remains the same.
string res = str.Substring(str.Length-5, 4);
string input = "test10015";
string result = input.Substring(4, 4);

Categories