←Select platform

GetStringValue Method

Summary
Gets a string value that is stored in the Value Field of the specified element.
Syntax
C#
C++/CLI
Java
public string GetStringValue( 
   DicomElement element, 
   int index 
) 
public String getStringValue(DicomElement element, int index) 
public: 
String^ GetStringValue(  
   DicomElement^ element, 
   int index 
)  

Parameters

element
An item in the Data Set.

index
The zero-based index of the string value to retrieve, when more than one value is stored in the Value Field.

Return Value

A string value stored in the Value Field of the specified Data Element. It is null if the length of the Value Field is 0, the method was called for the incorrect VR type, or the method was called for a folder (sequence) element.

Remarks

The method can be used to get one string value at a time. Therefore, if multiple values are stored in the Value Field, the method needs to be called multiple times to get all the values. This method can be called only if the Value Representation of the Data Element is DicomVRType.AE, DicomVRType.CS, DicomVRType.LO, DicomVRType.LT, DicomVRType.SH, DicomVRType.ST, DicomVRType.UI, DicomVRType.UT, or DicomVRType.PN. For more information about Value Representations, refer to Default Value Representation Table.

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
public void DicomSetGetValueTest() 
{ 
   //Make sure to initialize the DICOM engine, this needs to be done only once  
   //In the whole application 
   DicomEngine.Startup(); 
   using (DicomDataSet dicomDataset = new DicomDataSet()) 
   { 
      dicomDataset.Reset(); 
      dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian); 
      DicomElement element = dicomDataset.InsertElement(null, false, DicomTag.CineRate, DicomVRType.IS, false, 0); 
      if (element != null) 
      { 
         dicomDataset.SetIntValue(element, new int[] { 30 }, 1); 
         int[] value = dicomDataset.GetIntValue(element, 0, 1);// can also call GetLongValue 
         Debug.Assert(value[0] == 30); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.ChannelMaximumValue, DicomVRType.OB, false, 0); 
      if (element != null) 
      { 
         dicomDataset.SetByteValue(element, new byte[] { 55 }, 1); 
         byte[] value = dicomDataset.GetByteValue(element, 0, 1); 
         Debug.Assert(value[0] == 55); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.PregnancyStatus, DicomVRType.US, false, 0); 
      if (element != null) 
      { 
         dicomDataset.SetShortValue(element, new short[] { 2 }, 1); 
         short[] value = dicomDataset.GetShortValue(element, 0, 1); 
         Debug.Assert(value[0] == 2); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.SliceLocation, DicomVRType.DS, false, 0); 
      if (element != null) 
      { 
         dicomDataset.SetDoubleValue(element, new double[] { 10.5 }, 1); 
         double[] value = dicomDataset.GetDoubleValue(element, 0, 1); 
         Debug.Assert(value[0] == 10.5); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.PresentationPixelMagnificationRatio, DicomVRType.FL, false, 0); 
      if (element != null) 
      { 
         dicomDataset.SetFloatValue(element, new float[] { 3.2F }, 1); 
         float[] value = dicomDataset.GetFloatValue(element, 0, 1); 
         Debug.Assert(value[0] == 3.2F); 
 
         // Or you can use this overload 
         dicomDataset.SetFloatValue(element, 4.0F); 
         value = dicomDataset.GetFloatValue(element, 0, 1); 
         Debug.Assert(value[0] == 4.0F); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.InstanceCreationDate, DicomVRType.DA, false, 0); 
      if (element != null) 
      { 
         DicomDateValue[] newvalue = new DicomDateValue[1]; 
         newvalue[0].Year = 2004; 
         newvalue[0].Month = 1; 
         newvalue[0].Day = 8; 
         dicomDataset.SetDateValue(element, newvalue); 
         DicomDateValue[] value = dicomDataset.GetDateValue(element, 0, 1); 
         Debug.Assert((value[0].Year == 2004) && (value[0].Month == 1) && (value[0].Day == 8)); 
 
         // Or you can use the SetDateValue overload that takes a single DicomDateValue 
         dicomDataset.SetDateValue(element, new DicomDateValue(1961, 6, 5)); 
         value = dicomDataset.GetDateValue(element, 0, 1); 
         Debug.Assert((value[0].Year == 1961) && (value[0].Month == 6) && (value[0].Day == 5)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.InstanceCreationTime, DicomVRType.TM, false, 0); 
      if (element != null) 
      { 
         DicomTimeValue[] newvalue = new DicomTimeValue[1]; 
         newvalue[0].Hours = 2; 
         newvalue[0].Minutes = 3; 
         newvalue[0].Seconds = 5; 
         dicomDataset.SetTimeValue(element, newvalue); 
         DicomTimeValue[] value = dicomDataset.GetTimeValue(element, 0, 1); 
         Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.AcquisitionDateTime, DicomVRType.DT, false, 0); 
      if (element != null) 
      { 
         DicomDateTimeValue[] newvalue = new DicomDateTimeValue[1]; 
         newvalue[0].Year = 2004; 
         newvalue[0].Month = 1; 
         newvalue[0].Day = 8; 
         newvalue[0].Hours = 2; 
         newvalue[0].Minutes = 3; 
         newvalue[0].Seconds = 5; 
         dicomDataset.SetDateTimeValue(element, newvalue); 
         DicomDateTimeValue[] value = dicomDataset.GetDateTimeValue(element, 0, 1); 
         Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.PatientAge, DicomVRType.AS, false, 0); 
      if (element != null) 
      { 
         DicomAgeValue[] newvalue = new DicomAgeValue[1]; 
         newvalue[0].Number = 25; 
         newvalue[0].Reference = DicomAgeReferenceType.Days; 
         dicomDataset.SetAgeValue(element, newvalue); 
         DicomAgeValue[] value = dicomDataset.GetAgeValue(element, 0, 1); 
         Debug.Assert((value[0].Number == 25)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); 
      if (element != null) 
      { 
         dicomDataset.FreeElementValue(element); 
         dicomDataset.SetStringValue(element, "John Doe", DicomCharacterSetType.Default); 
         Debug.Assert(dicomDataset.GetElementValueCount(element) == 1); 
         Debug.Assert(dicomDataset.GetStringValue(element, 0) == "John Doe"); 
      } 
 
      byte[] inPreamble = new byte[128]; 
      for (int i = 0; i < 128; i++) 
      { 
         inPreamble[i] = (byte)i; 
      } 
      dicomDataset.SetPreamble(inPreamble, 0, 128); 
      byte[] outPreamble = dicomDataset.GetPreamble(128); 
 
      // Or you can use this overload which takes an offset 
      dicomDataset.GetPreamble(out outPreamble, 0, 128); 
 
      Debug.Assert(inPreamble.Length == outPreamble.Length); 
 
      element = dicomDataset.FindFirstElement(element, DicomTag.NumberOfRemainingSubOperations, true); 
      if (element != null) 
      { 
         //We don't really need to do this 
         dicomDataset.FreeElementValue(element); 
         byte[] inBinaryValue = new byte[2]; 
         inBinaryValue[0] = 0; 
         inBinaryValue[1] = 1; 
         dicomDataset.SetBinaryValue(element, inBinaryValue, 2); 
         byte[] outBinaryValue = dicomDataset.GetBinaryValue(element, 2); 
         Debug.Assert((outBinaryValue[0] == 0) && (outBinaryValue[1] == 1)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.StudyDate, DicomVRType.DA, false, 0); 
      if (element != null) 
      { 
         DicomDateValue date1 = new DicomDateValue(); 
         date1.Day = 1; 
         date1.Month = 2; 
         date1.Year = 2005; 
         DicomDateRangeValue[] newvalue = new DicomDateRangeValue[1]; 
         newvalue[0].Date1 = date1; 
         newvalue[0].Type = DicomRangeType.Lower; 
         dicomDataset.SetDateRangeValue(element, newvalue); 
         DicomDateRangeValue value = dicomDataset.GetDateRangeValue(element, 0); 
         Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Date1.Year == 2005)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.StudyTime, DicomVRType.TM, false, 0); 
      if (element != null) 
      { 
         DicomTimeValue time1 = new DicomTimeValue(); 
         time1.Hours = 2; 
         time1.Minutes = 1; 
         time1.Seconds = 3; 
         DicomTimeRangeValue[] newvalue = new DicomTimeRangeValue[1]; 
         newvalue[0].Time1 = time1; 
         newvalue[0].Type = DicomRangeType.Lower; 
         dicomDataset.SetTimeRangeValue(element, newvalue); 
         DicomTimeRangeValue value = dicomDataset.GetTimeRangeValue(element, 0); 
         Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Time1.Hours == 2)); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.PatientID, DicomVRType.LO, false, 0); 
      if (element != null) 
      { 
         dicomDataset.SetConvertValue(element, "154-4485", 1); 
         Debug.Assert(dicomDataset.GetConvertValue(element) == "154-4485"); 
      } 
 
      element = dicomDataset.InsertElement(null, false, DicomTag.SelectorULValue, DicomVRType.UL, false, 0); 
      if (element != null) 
      { 
         // Set two unsigned integer values (minimum and maximum unsigned 32-bit values) 
         long[] values = new long[] { 0, 4294967295 }; 
         dicomDataset.SetLongValue(element, values, 2); 
 
         string s = dicomDataset.GetConvertValue(element); 
         Debug.Assert(dicomDataset.GetConvertValue(element) == "0\\4294967295"); 
      } 
 
      dicomDataset.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None); 
   } 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom Assembly