Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a csv file that I'm reading in my azure function:

CSV FILE:

A B C
test test11 22
11 33 test


C# code:

C#
public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function started at: {DateTime.Now}");
            Thread.Sleep(2000);
            log.LogInformation($"C# Timer trigger function completed at: {DateTime.Now}");
            var path = @"C:\Users\sandurpr\Desktop\C# ....COA-Blanket-TB.csv";
            string csvData = File.ReadAllText(path);
            Console.WriteLine(csvData);


Requirement:

I want the user to check if the values in any row of any column is an integer or string.
if it is string then print string else print integer.
e.g when user inputs the row and column:
column: 2
row :1
string (test11)


Thank you.

What I have tried:

I tried declaring the columns first and assigning it to int or string and then calling each column to check if there is integer or string. But this didnt work out.
Posted
Updated 19-Sep-20 13:57pm

 
Share this answer
 
1 Key question: does your CSV data have an initial row that names colums in a way you can easily infer the column data type ?

2 If you are using zero based indexing: column: 2 row :1 ... is 22.

3 Are there any other numeric types you need to handle other than Int32 ?

There are many CP articles with code for CSV processing that might save you a lot of time; here's a recent one:[^], For more: [^].

This discussion on SO describes several approaches to CSV validation; most of them involve conversion to a DataSet, or Class structureL [^].

If you need to test a string for numeric conversion: Double.TryParse will return 'true for all types of numbers: decimal, float, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900