←Select platform

SetStringValue(DicomElement,string,DicomCharacterSetType) Method

Summary

Sets the string value(s) of a Data Element.

Syntax
C#
VB
C++
Java
public bool SetStringValue( 
   DicomElement element, 
   string value, 
   DicomCharacterSetType characterSet 
) 
Public Overloads Function SetStringValue( _ 
   ByVal element As DicomElement, _ 
   ByVal value As String, _ 
   ByVal characterSet As DicomCharacterSetType _ 
) As Boolean 
public boolean setStringValue(DicomElement element, String value) 
public: 
bool SetStringValue(  
   DicomElement^ element, 
   String^ value, 
   DicomCharacterSetType characterSet 
)  

Parameters

element
An item in the Data Set.

value
Character string that contains the string value to set.

characterSet
Character set to use when inserting the input string.

Return Value

true if the string value(s) were set successfully. false if could not set the string value(s) of the Data Element.

Remarks

This method can be called only if the Value Representation of the Data Element is:

For more information about Value Representations, refer to Default Value Representation Table.

Example

This example shows how to use the various overloads of SetStringValue and SetStringValuePtr to write a japanese string as the value of a DICOM element in a DicomDataSet

C#
VB
using Leadtools; 
using Leadtools.Dicom; 
 
/// 
private void DicomSetStringValueTest() 
{ 
   DicomEngine.Startup(); 
 
   DicomDataSet ds = new DicomDataSet(); 
   string japaneseText1 = "亜美"; 
   string japaneseText2 = "千香子"; 
   string[] japaneseStrings = { japaneseText1, japaneseText2 }; 
   DicomElement element; 
 
   // Example 1 - uses Specific Character Set Attribute (0008,0005) to set one string 
   ds.Reset(); 
   element = ds.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); 
   ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "ISO_IR 192");     // Unicode in UTF-8 
   ds.SetStringValue(element, japaneseText1); 
   string result = ds.GetStringValue(element, 0); 
   Debug.Assert(result == japaneseText1); 
 
   // Example 2 - uses Specific Character Set Attribute (0008,0005) to set two strings 
   ds.Reset(); 
   element = ds.InsertElement(null, false, DicomTag.OtherPatientNames, DicomVRType.PN, false, 0); 
   ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "ISO_IR 192");     // Unicode in UTF-8 
   ds.SetStringValue(element, japaneseStrings); 
   Debug.Assert(ds.GetStringValue(element, 0) == japaneseStrings[0]); 
   Debug.Assert(ds.GetStringValue(element, 1) == japaneseStrings[1]); 
 
   // Example 3 - pass in a DicomCharacterSet and set one string 
   ds.Reset(); 
   element = ds.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); 
   ds.SetStringValue(element, japaneseText1, DicomCharacterSetType.UnicodeInUtf8); 
   result = ds.GetStringValue(element, 0); 
   Debug.Assert(result == japaneseText1); 
 
   // Example 4 -- pass in a DicomCharacterSet and set two strings 
   ds.Reset(); 
   element = ds.InsertElement(null, false, DicomTag.OtherPatientNames, DicomVRType.PN, false, 0); 
   ds.SetStringValue(element, japaneseStrings, DicomCharacterSetType.UnicodeInUtf8); 
   Debug.Assert(ds.GetStringValue(element, 0) == japaneseStrings[0]); 
   Debug.Assert(ds.GetStringValue(element, 1) == japaneseStrings[1]); 
 
   // Example 5 -- uses Specific Character Set Attribute (0008,0005) to set one string using IntPtr 
   ds.Reset(); 
   GCHandle pinnedArray = GCHandle.Alloc(japaneseText1, GCHandleType.Pinned); 
   IntPtr pointer = pinnedArray.AddrOfPinnedObject(); 
   element = ds.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); 
   ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "ISO_IR 192");     // Unicode in UTF-8 
   ds.SetStringValuePtr(element, pointer, 1); 
   result = ds.GetStringValue(element, 0); 
   Debug.Assert(result == japaneseText1); 
   pinnedArray.Free(); 
 
   DicomEngine.Shutdown(); 
} 
Imports Leadtools 
Imports Leadtools.Dicom 
 
''' 
Private Sub DicomSetStringValueTest() 
   DicomEngine.Startup() 
 
   Dim ds As New DicomDataSet() 
   Dim japaneseText1 As String = "亜美" 
   Dim japaneseText2 As String = "千香子" 
   Dim japaneseStrings() As String = {japaneseText1, japaneseText2} 
   Dim element As DicomElement 
 
   ' Example 1 - uses Specific Character Set Attribute (0008,0005) to set one string 
   ds.Reset() 
   element = ds.InsertElement(Nothing, False, DicomTag.PatientName, DicomVRType.PN, False, 0) 
   ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "ISO_IR 192") ' Unicode in UTF-8 
   ds.SetStringValue(element, japaneseText1) 
   Dim result As String = ds.GetStringValue(element, 0) 
   Debug.Assert(result = japaneseText1) 
 
   ' Example 2 - uses Specific Character Set Attribute (0008,0005) to set two strings 
   ds.Reset() 
   element = ds.InsertElement(Nothing, False, DicomTag.OtherPatientNames, DicomVRType.PN, False, 0) 
   ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "ISO_IR 192") ' Unicode in UTF-8 
   ds.SetStringValue(element, japaneseStrings) 
   Debug.Assert(ds.GetStringValue(element, 0) = japaneseStrings(0)) 
   Debug.Assert(ds.GetStringValue(element, 1) = japaneseStrings(1)) 
 
   ' Example 3 - pass in a DicomCharacterSet and set one string 
   ds.Reset() 
   element = ds.InsertElement(Nothing, False, DicomTag.PatientName, DicomVRType.PN, False, 0) 
   ds.SetStringValue(element, japaneseText1, DicomCharacterSetType.UnicodeInUtf8) 
   result = ds.GetStringValue(element, 0) 
   Debug.Assert(result = japaneseText1) 
 
   ' Example 4 -- pass in a DicomCharacterSet and set two strings 
   ds.Reset() 
   element = ds.InsertElement(Nothing, False, DicomTag.OtherPatientNames, DicomVRType.PN, False, 0) 
   ds.SetStringValue(element, japaneseStrings, DicomCharacterSetType.UnicodeInUtf8) 
   Debug.Assert(ds.GetStringValue(element, 0) = japaneseStrings(0)) 
   Debug.Assert(ds.GetStringValue(element, 1) = japaneseStrings(1)) 
 
   ' Example 5 -- uses Specific Character Set Attribute (0008,0005) to set one string using IntPtr 
   ds.Reset() 
   Dim pinnedArray As GCHandle = GCHandle.Alloc(japaneseText1, GCHandleType.Pinned) 
   Dim pointer As IntPtr = pinnedArray.AddrOfPinnedObject() 
   element = ds.InsertElement(Nothing, False, DicomTag.PatientName, DicomVRType.PN, False, 0) 
   ds.InsertElementAndSetValue(DicomTag.SpecificCharacterSet, "ISO_IR 192") ' Unicode in UTF-8 
   ds.SetStringValuePtr(element, pointer, 1) 
   result = ds.GetStringValue(element, 0) 
   Debug.Assert(result = japaneseText1) 
   pinnedArray.Free() 
 
   DicomEngine.Shutdown() 
End Sub 

Requirements

Target Platforms

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

Leadtools.Dicom Assembly